You are here

public function PanelizerEntityDefault::hook_menu in Panelizer 7.3

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

Implements a delegated hook_menu.

Overrides PanelizerEntityInterface::hook_menu

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function hook_menu(&$items) {
  if (!empty($this->plugin['entity path'])) {

    // Figure out where in the path the entity will be.
    $bits = explode('/', $this->plugin['entity path']);
    foreach ($bits as $count => $bit) {
      if (strpos($bit, '%') === 0) {
        $position = $count;
        break;
      }
    }
    if (!isset($position)) {
      return;
    }
    $total = count($bits);

    // Configure entity editing pages
    $base = array(
      'access callback' => 'panelizer_entity_plugin_callback_switcher',
      'access arguments' => array(
        $this->entity_type,
        'access',
        'admin',
        $position,
        'overview',
      ),
      'page callback' => 'panelizer_entity_plugin_switcher_page',
      'type' => MENU_LOCAL_TASK,
    );
    $items[$this->plugin['entity path'] . '/panelizer'] = array(
      'title' => 'Customize display',
      // make sure this is accessible to panelize entities with no defaults.
      'page arguments' => array(
        $this->entity_type,
        'overview',
        $position,
      ),
      'weight' => 11,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    ) + $base;
    $items[$this->plugin['entity path'] . '/panelizer/overview'] = array(
      'title' => 'Overview',
      'page arguments' => array(
        $this->entity_type,
        'overview',
        $position,
      ),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    ) + $base;
    if ($this->supports_revisions) {
      $rev_base = $base;
      $rev_base['load arguments'] = array(
        $position + 2,
      );
      $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer'] = array(
        'title' => 'Customize display',
        // Make sure this is accessible to panelize entities with no defaults.
        'page arguments' => array(
          $this->entity_type,
          'overview',
          $position,
        ),
        'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
        'type' => MENU_LOCAL_TASK,
        'weight' => 11,
      ) + $rev_base;

      // Integration with Workbench Moderation.
      if (module_exists('workbench_moderation') && $this->entity_type == 'node') {
        $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer']['type'] = MENU_CALLBACK;
      }
      $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/overview'] = array(
        'title' => 'Overview',
        'page arguments' => array(
          $this->entity_type,
          'overview',
          $position,
        ),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -100,
      ) + $rev_base;
    }

    // Put in all of our view mode based paths.
    $weight = 0;
    foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) {
      $items[$this->plugin['entity path'] . "/panelizer/{$view_mode}"] = array(
        'title' => $view_mode_info['label'],
        'page arguments' => array(
          $this->entity_type,
          'settings',
          $position,
          $view_mode,
        ),
        'access arguments' => array(
          $this->entity_type,
          'access',
          'admin',
          $position,
          'settings',
          $view_mode,
        ),
        'weight' => $weight++,
      ) + $base;
      if ($this->supports_revisions) {
        $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode] = array(
          'title' => $view_mode_info['label'],
          'page arguments' => array(
            $this->entity_type,
            'content',
            $position,
            $view_mode,
          ),
          'access arguments' => array(
            $this->entity_type,
            'access',
            'admin',
            $position,
            'content',
            $view_mode,
          ),
          'weight' => $weight++,
        ) + $base;
      }
      foreach (panelizer_operations() as $path => $operation) {
        $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path] = array(
          'title' => $operation['menu title'],
          'page arguments' => array(
            $this->entity_type,
            $path,
            $position,
            $view_mode,
          ),
          'access arguments' => array(
            $this->entity_type,
            'access',
            'admin',
            $position,
            $path,
            $view_mode,
          ),
          'weight' => $weight++,
        ) + $base;
        if (isset($operation['file'])) {
          $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path]['file'] = $operation['file'];
        }
        if (isset($operation['file path'])) {
          $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path]['file path'] = $operation['file path'];
        }
        if ($this->supports_revisions) {
          $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode . '/' . $path] = array(
            'title' => $operation['menu title'],
            'page arguments' => array(
              $this->entity_type,
              $path,
              $position,
              $view_mode,
            ),
            'access arguments' => array(
              $this->entity_type,
              'access',
              'admin',
              $position,
              $path,
              $view_mode,
            ),
            'weight' => $weight++,
          ) + $rev_base;
          if (isset($operation['file'])) {
            $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode . '/' . $path]['file'] = $operation['file'];
          }
          if (isset($operation['file path'])) {
            $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode . '/' . $path]['file path'] = $operation['file path'];
          }
        }
      }

      // Add our special reset item:
      $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/reset'] = array(
        'title' => t('Reset to Defaults'),
        'page arguments' => array(
          $this->entity_type,
          'reset',
          $position,
          $view_mode,
        ),
        'type' => MENU_CALLBACK,
      ) + $base;

      // Make the 'content' URLs the local default tasks.
      $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/content']['type'] = MENU_DEFAULT_LOCAL_TASK;
      if ($this->supports_revisions && isset($items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode . '/content']['type'])) {
        $items[$this->plugin['entity path'] . '/revisions/%panelizer_node_revision/panelizer/' . $view_mode . '/content']['type'] = MENU_DEFAULT_LOCAL_TASK;
      }
    }
  }
  if (!empty($items)) {
    ksort($items);
  }

  // Also add administrative links to the bundle.
  if (!empty($this->entity_admin_root)) {
    $this
      ->add_admin_links($this->entity_admin_root, $this->entity_admin_bundle, $items);
  }
}