コード例 #1
0
 /**
  * Helper function to add administrative menu items into an entity's already existing structure.
  *
  * While this very closely follows the administrative items placed into the
  * menu in admin.inc, it is a little bit different because of how bundles
  * are placed into the URL. So the code is close but not QUITE reusable
  * without going through some hoops.
  *
  * @param $root
  *   The root path. This will be something like 'admin/structure/types/manage/%'.
  *   Everything will be placed at $root/panelizer/*.
  * @param $bundle
  *   This is either the numeric position of the bundle or, for entity types
  *   that do not support bundles, a hard coded bundle string.
  * @param &$items
  *   The array of menu items this is being added to.
  */
 public function add_admin_links($root, $bundle, &$items)
 {
     // Node $root = 'admin/structure/types/manage/%
     // Taxonomy $root = 'admin/structure/taxonomy/%'
     // User $root = 'admin/config/people/accounts'
     $parts = explode('/', $root);
     $base_count = count($parts);
     // Configure settings pages.
     $settings_base = array('access callback' => 'panelizer_is_panelized', 'access arguments' => array($this->entity_type, $bundle), 'file' => 'includes/admin.inc');
     // This is the base tab that will be added. The weight is set
     // to try and make sure it stays to the right of manage fields
     // and manage display.
     $items[$root . '/panelizer'] = array('title' => 'Panelizer', 'page callback' => 'panelizer_allowed_content_page', 'page arguments' => array($this->entity_type, $bundle), 'type' => MENU_LOCAL_TASK, 'weight' => 5) + $settings_base;
     $items[$root . '/panelizer/allowed'] = array('title' => 'Allowed content', 'page callback' => 'panelizer_allowed_content_page', 'page arguments' => array($this->entity_type, $bundle), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10) + $settings_base;
     $weight = 1;
     foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) {
         $tabs_base = array('access callback' => 'panelizer_has_no_choice_callback', 'access arguments' => array($this->entity_type, $bundle, $view_mode), 'page arguments' => array($this->entity_type, $bundle, 'default', $view_mode), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/admin.inc', 'weight' => $weight++);
         $items[$root . '/panelizer/' . $view_mode] = array('access callback' => 'panelizer_is_panelized', 'title' => $view_mode_info['label'], 'page callback' => 'panelizer_default_list_or_settings_page') + $tabs_base;
         $index = 0;
         foreach (panelizer_operations() as $path => $operation) {
             $items[$root . '/panelizer/' . $view_mode . '/' . $path] = array('title' => $operation['menu title'], 'page callback' => $operation['admin callback'], 'weight' => $index - 4, 'type' => $index === 0 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK) + $tabs_base;
             if (isset($operation['file'])) {
                 $items[$root . '/panelizer/' . $view_mode . '/' . $path]['file'] = $operation['file'];
             }
             if (isset($operation['file path'])) {
                 $items[$root . '/panelizer/' . $view_mode . '/' . $path]['file path'] = $operation['file path'];
             }
             $index++;
         }
         $subtabs_base = array('access callback' => 'panelizer_administer_panelizer_default', 'access arguments' => array($this->entity_type, $bundle, $base_count + 2, $base_count + 1), 'page arguments' => array($this->entity_type, $bundle, $base_count + 2, $base_count + 1), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/admin.inc');
         $items[$root . '/panelizer/' . $view_mode . '/%'] = array('title' => 'Settings', 'page callback' => 'panelizer_default_settings_page', 'title callback' => 'panelizer_default_name_title_callback', 'type' => MENU_CALLBACK) + $subtabs_base;
         $index = 0;
         foreach (panelizer_operations() as $path => $operation) {
             $items[$root . '/panelizer/' . $view_mode . '/%/' . $path] = array('title' => $operation['menu title'], 'page callback' => $operation['admin callback'], 'weight' => $index - 4) + $subtabs_base;
             if (isset($operation['file'])) {
                 $items[$root . '/panelizer/' . $view_mode . '/%/' . $path]['file'] = $operation['file'];
             }
             if (isset($operation['file path'])) {
                 $items[$root . '/panelizer/' . $view_mode . '/%/' . $path]['file path'] = $operation['file path'];
             }
             $index++;
         }
         // This special tab isn't a normal operation because appears only
         // in the admin menu.
         $items[$root . '/panelizer/' . $view_mode . '/%/access'] = array('title' => 'Access', 'page callback' => 'panelizer_default_access_page', 'weight' => -2) + $subtabs_base;
         // Also make clones of all the export UI menu items. Again there is some
         // duplicated code here because of subtle differences.
         // Load the $plugin information.
         ctools_include('export-ui');
         $plugin = ctools_get_export_ui('panelizer_defaults');
         $ui_items = $plugin['menu']['items'];
         // Change the item to a tab.
         $ui_items['list']['type'] = MENU_LOCAL_TASK;
         $ui_items['list']['weight'] = -6;
         $ui_items['list']['title'] = 'List';
         // Menu local actions are weird.
         if (isset($ui_items['add']['path'])) {
             $ui_items['add']['path'] = 'list/add';
         }
         if (isset($ui_items['import']['path'])) {
             $ui_items['import']['path'] = 'list/import';
         }
         // Edit is being handled elsewhere.
         unset($ui_items['edit callback']);
         unset($ui_items['access']);
         unset($ui_items['list callback']);
         foreach (panelizer_operations() as $path => $operation) {
             $location = isset($operation['ui path']) ? $operation['ui path'] : $path;
             if (isset($ui_items[$location])) {
                 unset($ui_items[$location]);
             }
         }
         // Change the callbacks for everything.
         foreach ($ui_items as $key => $item) {
             // originally admin/config/content/panelizer/%panelizer_handler
             $ui_items[$key]['access callback'] = 'panelizer_has_choice_callback_view_mode';
             $ui_items[$key]['access arguments'] = array($this->entity_type, $bundle, $view_mode);
             $ui_items[$key]['page callback'] = 'panelizer_default_list_or_settings_page';
             $ui_items[$key]['page arguments'][0] = $view_mode;
             array_unshift($ui_items[$key]['page arguments'], '');
             array_unshift($ui_items[$key]['page arguments'], $bundle);
             array_unshift($ui_items[$key]['page arguments'], $this->entity_type);
             $ui_items[$key]['path'] = str_replace('list/', '', $ui_items[$key]['path']);
             // Some of the page arguments attempt to pass the eight argument (item
             // #7, starting at 0) to the callback in order to work on the display
             // object. However, for some entities this will end up being the $op
             // instead of the object name, e.g. 'clone' instead of
             // 'taxonomy_term:tags:default'.
             if (!empty($ui_items[$key]['page arguments'][5]) && is_numeric($bundle)) {
                 $ui_items[$key]['page arguments'][5] = $bundle + 3;
             }
         }
         foreach ($ui_items as $item) {
             // Add menu item defaults.
             $item += array('file' => 'export-ui.inc', 'file path' => drupal_get_path('module', 'ctools') . '/includes');
             $path = !empty($item['path']) ? $root . '/panelizer/' . $view_mode . '/' . $item['path'] : $root . '/panelizer/' . $view_mode;
             unset($item['path']);
             $items[$path] = $item;
         }
     }
 }
コード例 #2
0
 /**
  * Helper function to add administrative menu items into an entity's already existing structure.
  *
  * While this very closely follows the administrative items placed into the
  * menu in admin.inc, it is a little bit different because of how bundles
  * are placed into the URL. So the code is close but not QUITE reusable
  * without going through some hoops.
  *
  * @param $root
  *   The root path. This will be something like 'admin/structure/types/manage/%'.
  *   Everything will be placed at $root/panelizer/*.
  * @param $bundle
  *   This is either the numeric position of the bundle or, for entity types
  *   that do not support bundles, a hard coded bundle string.
  * @param &$items
  *   The array of menu items this is being added to.
  */
 public function add_admin_links($root, $bundle, &$items)
 {
     // Node $root = 'admin/structure/types/manage/%
     // Taxonomy $root = 'admin/structure/taxonomy/%'
     // User $root = 'admin/config/people/accounts'
     $parts = explode('/', $root);
     $base_count = count($parts);
     // Configure settings pages.
     $settings_base = array('access callback' => 'panelizer_is_panelized', 'access arguments' => array($this->entity_type, $bundle), 'file' => 'includes/admin.inc');
     // This is the base tab that will be added. The weight is set
     // to try and make sure it stays to the right of manage fields
     // and manage display.
     $items[$root . '/panelizer'] = array('title' => 'Panelizer', 'page callback' => 'panelizer_allowed_content_page', 'page arguments' => array($this->entity_type, $bundle), 'type' => MENU_LOCAL_TASK, 'weight' => 5) + $settings_base;
     $items[$root . '/panelizer/allowed'] = array('title' => 'Allowed content', 'page callback' => 'panelizer_allowed_content_page', 'page arguments' => array($this->entity_type, $bundle), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10) + $settings_base;
     $weight = 1;
     foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) {
         $tabs_base = array('access callback' => 'panelizer_has_no_choice_callback', 'access arguments' => array($this->entity_type, $bundle, $view_mode), 'page arguments' => array($this->entity_type, $bundle, 'default', $view_mode), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/admin.inc', 'weight' => $weight++);
         $items[$root . '/panelizer/' . $view_mode] = array('access callback' => 'panelizer_is_panelized', 'title' => $view_mode_info['label'], 'page callback' => 'panelizer_default_list_or_settings_page') + $tabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/settings'] = array('title' => 'Settings', 'page callback' => 'panelizer_default_settings_page', 'weight' => -5, 'type' => MENU_DEFAULT_LOCAL_TASK) + $tabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/context'] = array('title' => 'Contexts', 'page callback' => 'panelizer_default_context_page', 'weight' => -4) + $tabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/layout'] = array('title' => 'Layout', 'page callback' => 'panelizer_default_layout_page', 'weight' => -3) + $tabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/content'] = array('title' => 'Content', 'page callback' => 'panelizer_default_content_page', 'weight' => -2) + $tabs_base;
         $subtabs_base = array('access callback' => 'panelizer_administer_panelizer_default', 'access arguments' => array($this->entity_type, $bundle, $base_count + 2, $base_count + 1), 'page arguments' => array($this->entity_type, $bundle, $base_count + 2, $base_count + 1), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/admin.inc');
         $items[$root . '/panelizer/' . $view_mode . '/%'] = array('title' => 'Settings', 'page callback' => 'panelizer_default_settings_page', 'title callback' => 'panelizer_default_name_title_callback', 'type' => MENU_CALLBACK) + $subtabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/%/settings'] = array('title' => 'Settings', 'page callback' => 'panelizer_default_settings_page', 'weight' => -5) + $subtabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/%/context'] = array('title' => 'Contexts', 'page callback' => 'panelizer_default_context_page', 'weight' => -4) + $subtabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/%/layout'] = array('title' => 'Layout', 'page callback' => 'panelizer_default_layout_page', 'weight' => -3) + $subtabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/%/content'] = array('title' => 'Content', 'page callback' => 'panelizer_default_content_page', 'weight' => -2) + $subtabs_base;
         $items[$root . '/panelizer/' . $view_mode . '/%/access'] = array('title' => 'Access', 'page callback' => 'panelizer_default_access_page', 'weight' => -2) + $subtabs_base;
         // Also make clones of all the export UI menu items. Again there is some
         // duplicated code here because of subtle differences.
         // Load the $plugin information
         $plugin = ctools_get_export_ui('panelizer_defaults');
         $ui_items = $plugin['menu']['items'];
         // Change the item to a tab.
         $ui_items['list']['type'] = MENU_LOCAL_TASK;
         $ui_items['list']['weight'] = -6;
         $ui_items['list']['title'] = 'List';
         // menu local actions are weird.
         $ui_items['add']['path'] = 'list/add';
         $ui_items['import']['path'] = 'list/import';
         // Edit is being handled elsewhere:
         unset($ui_items['edit']);
         unset($ui_items['edit callback']);
         unset($ui_items['list callback']);
         unset($ui_items['context']);
         unset($ui_items['content']);
         unset($ui_items['layout']);
         unset($ui_items['access']);
         // Change the callbacks for everything:
         foreach ($ui_items as $key => $item) {
             // originally admin/config/content/panelizer/%panelizer_handler
             $ui_items[$key]['access callback'] = 'panelizer_has_choice_callback';
             $ui_items[$key]['access arguments'] = array($this->entity_type, $bundle, '');
             $ui_items[$key]['page callback'] = 'panelizer_export_ui_switcher_page';
             array_unshift($ui_items[$key]['page arguments'], $bundle);
             array_unshift($ui_items[$key]['page arguments'], $this->entity_type);
             $ui_items[$key]['path'] = str_replace('list/', '', $ui_items[$key]['path']);
         }
         foreach ($ui_items as $item) {
             // Add menu item defaults.
             $item += array('file' => 'export-ui.inc', 'file path' => drupal_get_path('module', 'ctools') . '/includes');
             $path = !empty($item['path']) ? $root . '/panelizer/' . $view_mode . '/' . $item['path'] : $root . '/panelizer/' . $view_mode;
             unset($item['path']);
             $items[$path] = $item;
         }
     }
 }