From 76efcb077820eb1e9dbf3e1be8c921e00a0f1291 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Fri, 25 Apr 2014 16:13:11 +0200 Subject: [PATCH] added simplenews local actions + change template selection from query to path --- materio_admin.module | 51 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/materio_admin.module b/materio_admin.module index 86e28112..d34b7888 100644 --- a/materio_admin.module +++ b/materio_admin.module @@ -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;