You are here

public function PanelizerEntityDefault::add_admin_links in Panelizer 7.2

Same name and namespace in other branches
  1. 7.3 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::add_admin_links()

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.

Parameters

$root: The root path. This will be something like 'admin/structure/types/manage/%'. Everything will be placed at $root/panelizer/*.

$bundle: This is either the numeric position of the bundle or, for entity types that do not support bundles, a hard coded bundle string.

&$items: The array of menu items this is being added to.

1 call to PanelizerEntityDefault::add_admin_links()
PanelizerEntityDefault::hook_menu in plugins/entity/PanelizerEntityDefault.class.php
Implements a delegated hook_menu.

File

plugins/entity/PanelizerEntityDefault.class.php, line 337
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

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' => 'Available content',
    'page callback' => 'panelizer_allowed_content_page',
    'page arguments' => array(
      $this->entity_type,
      $bundle,
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  ) + $settings_base;
  $tabs_base = array(
    'access callback' => 'panelizer_has_no_choice_callback',
    'access arguments' => array(
      $this->entity_type,
      $bundle,
    ),
    'page arguments' => array(
      $this->entity_type,
      $bundle,
      'default',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/admin.inc',
  );
  $items[$root . '/panelizer/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'panelizer_default_settings_page',
    'weight' => -5,
  ) + $tabs_base;
  $items[$root . '/panelizer/context'] = array(
    'title' => 'Contexts',
    'page callback' => 'panelizer_default_context_page',
    'weight' => -4,
  ) + $tabs_base;
  $items[$root . '/panelizer/layout'] = array(
    'title' => 'Layout',
    'page callback' => 'panelizer_default_layout_page',
    'weight' => -3,
  ) + $tabs_base;
  $items[$root . '/panelizer/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,
    ),
    'page arguments' => array(
      $this->entity_type,
      $bundle,
      $base_count + 2,
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'includes/admin.inc',
  );
  $items[$root . '/panelizer/list/%'] = array(
    'title' => 'Settings',
    'page callback' => 'panelizer_default_settings_page',
    'title callback' => 'panelizer_default_name_title_callback',
    'type' => MENU_CALLBACK,
  ) + $subtabs_base;
  $items[$root . '/panelizer/list/%/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'panelizer_default_settings_page',
    'weight' => -5,
  ) + $subtabs_base;
  $items[$root . '/panelizer/list/%/context'] = array(
    'title' => 'Contexts',
    'page callback' => 'panelizer_default_context_page',
    'weight' => -4,
  ) + $subtabs_base;
  $items[$root . '/panelizer/list/%/layout'] = array(
    'title' => 'Layout',
    'page callback' => 'panelizer_default_layout_page',
    'weight' => -3,
  ) + $subtabs_base;
  $items[$root . '/panelizer/list/%/content'] = array(
    'title' => 'Content',
    'page callback' => 'panelizer_default_content_page',
    'weight' => -2,
  ) + $subtabs_base;
  $items[$root . '/panelizer/list/%/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);
  }
  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/' . $item['path'] : $root . '/panelizer';
    unset($item['path']);
    $items[$path] = $item;
  }
}