added simplenews local actions + change template selection from query to path

This commit is contained in:
Bachir Soussi Chiadmi 2014-04-25 16:13:11 +02:00
parent f6d5c40ae2
commit 76efcb0778

View File

@ -44,10 +44,8 @@ function materio_admin_menu() {
'page arguments' => array('simplenews'),
'access callback' => 'node_access',
'access arguments' => array('create', 'simplenews'),
// 'description' => $type->description,
'file path' => drupal_get_path('module', 'node'),
'file' => 'node.pages.inc',
'options' => array('query'=>array('cat'=>$tid))
);
}
}
@ -81,7 +79,47 @@ function materio_admin_menu_alter(&$items){
// $items['admin/content/add/simplenews/'.$tid]
// }
// }
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function materio_admin_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'admin/people/simplenews') {
$item = menu_get_item('admin/content/simplenews');
if ($item['access']) {
$item['title'] = 'Go to '.$item['title'];
$data['actions']['output'][] = array(
'#theme' => 'menu_local_task',
'#link' => $item,
);
}
}
if ($root_path == 'admin/content/simplenews') {
$cats = simplenews_category_list();
foreach ($cats as $tid => $name) {
$item = menu_get_item('node/add/simplenews/'.$tid);
$item['title'] = 'Create new '.$name;
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_task',
'#link' => $item,
);
}
}
$item = menu_get_item('admin/people/simplenews');
if ($item['access']) {
$item['title'] = 'Go to '.$item['title'];
$data['actions']['output'][] = array(
'#theme' => 'menu_local_task',
'#link' => $item,
);
}
}
}
/**
@ -94,9 +132,12 @@ function materio_admin_form_simplenews_node_form_alter(&$form, &$form_state, $fo
// dsm($_GET, 'GET');
if(!$form['nid']['#value']){
if(isset($_GET['cat'])){
$cat = $_GET['cat'];
$cats = simplenews_category_list();
$cats_tids = array_keys($cats);
$q = parse_url($_GET['q']);
$cat = array_pop(explode('/', $q['path']));
// dsm($cat, 'cat');
if(in_array($cat, $cats_tids)){
// prepopulate type of news
$form['field_simplenews_term']['und']['#default_value'] = $cat;
$form['field_simplenews_term']['und']['#disabled'] = true;