You are here

public function PanelizerEntityDefault::hook_permission in Panelizer 7.3

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

Implements a delegated hook_permission.

Overrides PanelizerEntityInterface::hook_permission

File

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

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function hook_permission(&$items) {
  $entity_info = entity_get_info($this->entity_type);

  // Make a permission for each bundle we control.
  foreach ($this->plugin['bundles'] as $bundle => $settings) {

    // This is before the if because it shows up regardless of whether
    // or not a type is panelized.
    $items["administer panelizer {$this->entity_type} {$bundle} defaults"] = array(
      'title' => t('%entity_name %bundle_name: Administer Panelizer default panels, allowed content and settings.', array(
        '%entity_name' => $entity_info['label'],
        '%bundle_name' => $entity_info['bundles'][$bundle]['label'],
      )),
      'description' => t('Users with this permission can fully administer panelizer for this entity bundle.'),
    );
    if (empty($settings['status'])) {
      continue;
    }
    $items["administer panelizer {$this->entity_type} {$bundle} overview"] = array(
      'title' => t('%entity_name %bundle_name: Administer Panelizer overview', array(
        '%entity_name' => $entity_info['label'],
        '%bundle_name' => $entity_info['bundles'][$bundle]['label'],
      )),
      'description' => t('Allow access to the panelizer overview page for the entity type/bundle. Note: This permission will be required for panelizer tabs to appear on an entity.'),
    );
    foreach (panelizer_operations() as $path => $operation) {
      $items["administer panelizer {$this->entity_type} {$bundle} {$path}"] = array(
        'title' => t('%entity_name %bundle_name: Administer Panelizer @operation', array(
          '%entity_name' => $entity_info['label'],
          '%bundle_name' => $entity_info['bundles'][$bundle]['label'],
          '@operation' => $operation['link title'],
        )),
      );
    }

    // Account for the choice permission when dealing with view modes.
    foreach ($settings['view modes'] as $view_mode => $view_mode_settings) {
      if (!empty($view_mode_settings['choice'])) {
        $items["administer panelizer {$this->entity_type} {$bundle} choice"] = array(
          'title' => t('%entity_name %bundle_name: Choose panels', array(
            '%entity_name' => $entity_info['label'],
            '%bundle_name' => $entity_info['bundles'][$bundle]['label'],
          )),
          'description' => t('Allows the user to choose which default display the entity uses.'),
        );

        // Break out of loop after finding one we just need to see if we should
        // enable the permission.
        break;
      }
    }
  }
}