You are here

function panelizer_panelizer_task_contextual_link in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 plugins/task_handlers/panelizer_node.inc \panelizer_panelizer_task_contextual_link()

Provide appropriate contextual links for Panelizer controlled entities.

1 string reference to 'panelizer_panelizer_task_contextual_link'
panelizer_node.inc in plugins/task_handlers/panelizer_node.inc
This is the task handler plugin to handle an entity view. NOTE: This is named panelizer_node for historical reasons. It is too much of a pain to change the name of a task handler. This panelizes any entity not just a node.

File

plugins/task_handlers/panelizer_node.inc, line 130
This is the task handler plugin to handle an entity view. NOTE: This is named panelizer_node for historical reasons. It is too much of a pain to change the name of a task handler. This panelizes any entity not just a node.

Code

function panelizer_panelizer_task_contextual_link($handler, $plugin, $contexts, $args) {
  $links = array();
  $context = _panelizer_panelizer_task_get_context($handler, $contexts);
  if (empty($context->data)) {
    return;
  }
  $entity =& $context->data;

  // Only show links for this view mode.
  $view_mode = 'page_manager';
  if (empty($entity->panelizer[$view_mode])) {
    return FALSE;
  }
  $panelizer = $entity->panelizer[$view_mode];

  // One of these two will always be set.
  $entity_type = !empty($panelizer->entity_type) ? $panelizer->entity_type : $panelizer->panelizer_type;
  if ($entity_handler = panelizer_entity_plugin_get_handler($entity_type)) {
    list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);

    // @todo there's code on the entity handler to do this path thing for us.
    $bits = explode('/', $entity_handler->plugin['entity path']);
    foreach ($bits as $count => $bit) {
      if (strpos($bit, '%') === 0) {
        $bits[$count] = $entity_id;
      }
    }
    $bits[] = 'panelizer';
    $bits[] = $view_mode;
    $base_path = implode('/', $bits);
    if ($entity_handler
      ->panelizer_access('settings', $entity, $view_mode)) {
      $links['settings'] = array(
        'title' => t("Edit custom display settings"),
        'href' => "{$base_path}/settings",
      );
    }
    if ($entity_handler
      ->panelizer_access('context', $entity, $view_mode)) {
      $links['context'] = array(
        'title' => t('Edit custom display contexts'),
        'href' => "{$base_path}/context",
      );
    }
    if ($entity_handler
      ->panelizer_access('layout', $entity, $view_mode)) {
      $links['layout'] = array(
        'title' => t('Edit custom display layout'),
        'href' => "{$base_path}/layout",
      );
    }
    if ($entity_handler
      ->panelizer_access('content', $entity, $view_mode)) {
      $links['content'] = array(
        'title' => t('Edit custom display content'),
        'href' => "{$base_path}/content",
      );
    }

    // Work out what the default display is called.
    $default_display_name = $entity_handler
      ->get_default_display_default_name($bundle, $view_mode);

    // If the default display is defined, add links to edit it.
    if (!empty($default_display_name)) {
      $template_base_path = "admin/structure/types/manage/{$bundle}/panelizer/{$view_mode}/{$default_display_name}";
      if ($entity_handler
        ->panelizer_access('settings', $entity, $view_mode)) {
        $links['default_settings'] = array(
          'title' => t('Edit default display settings'),
          'href' => "{$template_base_path}/settings",
        );
      }
      if ($entity_handler
        ->panelizer_access('context', $entity, $view_mode)) {
        $links['default_context'] = array(
          'title' => t('Edit default display contexts'),
          'href' => "{$template_base_path}/context",
        );
      }
      if ($entity_handler
        ->panelizer_access('layout', $entity, $view_mode)) {
        $links['default_layout'] = array(
          'title' => t('Edit default display layout'),
          'href' => "{$template_base_path}/layout",
        );
      }
      if ($entity_handler
        ->panelizer_access('content', $entity, $view_mode)) {
        $links['default_content'] = array(
          'title' => t('Edit default display content'),
          'href' => "{$template_base_path}/content",
        );
      }
    }
  }
  return $links;
}