You are here

public function PanelizerEntityDefault::hook_views_data_alter in Panelizer 7.2

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

Implement views support for panelizer entity types.

Overrides PanelizerEntityInterface::hook_views_data_alter

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function hook_views_data_alter(&$items) {
  $entity_info = entity_get_info($this->entity_type);
  if (!empty($entity_info['base table'])) {
    $table = $entity_info['base table'];
    $items[$table]['panelizer_link'] = array(
      'field' => array(
        'title' => t('Panelizer link'),
        'help' => t('Provide a link to panelizer-related operations on the content.'),
        'handler' => 'panelizer_handler_field_link',
        'entity_type' => $this->entity_type,
      ),
    );
    $items[$table]['panelizer_status'] = array(
      'field' => array(
        'title' => t('Panelizer status'),
        'help' => t('Display whether an entity is panelized and which panelizer option it is using.'),
        'handler' => 'panelizer_handler_panelizer_status',
        'entity_type' => $this->entity_type,
      ),
    );

    // Join on revision id if possible or entity id if not.
    if (!empty($entity_info['entity keys']['revision'])) {
      $id_field = $entity_info['entity keys']['revision'];
      $field = 'revision_id';
    }
    else {
      $id_field = $entity_info['entity keys']['id'];
      $field = 'entity_id';
    }
    $items['panelizer_entity_' . $table]['table']['join'] = array(
      $table => array(
        'handler' => 'views_join',
        'table' => 'panelizer_entity',
        'left_table' => $table,
        'left_field' => $id_field,
        'field' => $field,
        'extra' => array(
          array(
            'field' => 'entity_type',
            'value' => $this->entity_type,
            'operator' => '=',
          ),
        ),
      ),
    );
    $items['panelizer_entity_' . $table]['table']['group'] = $items[$table]['table']['group'];
    $items['panelizer_entity_' . $table]['name'] = array(
      'filter' => array(
        'title' => t('Panelizer status'),
        'help' => t('Filter based upon panelizer status.'),
        'handler' => 'panelizer_handler_filter_panelizer_status',
        'entity_type' => $this->entity_type,
      ),
    );
  }
}