You are here

function panelizer_panelizer_task_contextual_link in Panelizer 7.2

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

Provide appropriate contextual links for Panelizer controled 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 102
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;
  if (empty($entity->panelizer)) {
    return FALSE;
  }
  $panelizer = $entity->panelizer;

  // 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);
    $bits = explode('/', $entity_handler->plugin['entity path']);
    foreach ($bits as $count => $bit) {
      if (strpos($bit, '%') === 0) {
        $bits[$count] = $entity_id;
      }
    }
    $bits[] = 'panelizer';
    $base_path = implode('/', $bits);
    if ($entity_handler
      ->panelizer_access('settings', $entity)) {
      $links['settings'] = array(
        'title' => t('Edit panelizer settings'),
        'href' => "{$base_path}/settings",
      );
    }
    if ($entity_handler
      ->panelizer_access('context', $entity)) {
      $links['context'] = array(
        'title' => t('Edit panelizer contexts'),
        'href' => "{$base_path}/context",
      );
    }
    if ($entity_handler
      ->panelizer_access('layout', $entity)) {
      $links['layout'] = array(
        'title' => t('Edit panelizer layout'),
        'href' => "{$base_path}/layout",
      );
    }
    if ($entity_handler
      ->panelizer_access('content', $entity)) {
      $links['content'] = array(
        'title' => t('Edit panelizer content'),
        'href' => "{$base_path}/content",
      );
    }
  }
  return $links;
}