You are here

class Panelizer in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/Panelizer.php \Drupal\panelizer\Panelizer
  2. 8.4 src/Panelizer.php \Drupal\panelizer\Panelizer

The Panelizer service.

Hierarchy

Expanded class hierarchy of Panelizer

2 files declare their use of Panelizer
PanelizerDefaultPanelsStorageTest.php in tests/src/Unit/PanelizerDefaultPanelsStorageTest.php
PanelizerFieldPanelsStorageTest.php in tests/src/Unit/PanelizerFieldPanelsStorageTest.php
3 string references to 'Panelizer'
panelizer.info.yml in ./panelizer.info.yml
panelizer.info.yml
panelizer.services.yml in ./panelizer.services.yml
panelizer.services.yml
Panelizer::setPanelizerSettings in src/Panelizer.php
1 service uses Panelizer
panelizer in ./panelizer.services.yml
Drupal\panelizer\Panelizer

File

src/Panelizer.php, line 28

Namespace

Drupal\panelizer
View source
class Panelizer implements PanelizerInterface {
  use StringTranslationTrait;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The entity type bundle info manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * The entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
   */
  protected $entityFieldManager;

  /**
   * The field type manager.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypeManager;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The current user service.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * The Panelizer entity manager.
   *
   * @var \Drupal\panelizer\Plugin\PanelizerEntityManager
   */
  protected $panelizerEntityManager;

  /**
   * The Panels display manager.
   *
   * @var \Drupal\Panels\PanelsDisplayManagerInterface
   */
  protected $panelsManager;

  /**
   * The context mapper.
   *
   * @var \Drupal\ctools\ContextMapperInterface
   */
  protected $contextMapper;

  /**
   * Constructs a Panelizer.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
   *   The entity type bundle info manager.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager.
   * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
   *   The field type manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   *   The current user service.
   * @param \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_entity_manager
   *   The Panelizer entity manager.
   * @param \Drupal\panels\PanelsDisplayManagerInterface $panels_manager
   *   The Panels display manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   * @param \Drupal\ctools\ContextMapperInterface $context_mapper
   *   The context mapper service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, ModuleHandlerInterface $module_handler, AccountProxyInterface $current_user, PanelizerEntityManager $panelizer_entity_manager, PanelsDisplayManagerInterface $panels_manager, TranslationInterface $string_translation, ContextMapperInterface $context_mapper) {
    $this->entityTypeManager = $entity_type_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->entityFieldManager = $entity_field_manager;
    $this->fieldTypeManager = $field_type_manager;
    $this->moduleHandler = $module_handler;
    $this->currentUser = $current_user;
    $this->panelizerEntityManager = $panelizer_entity_manager;
    $this->panelsManager = $panels_manager;
    $this->stringTranslation = $string_translation;
    $this->contextMapper = $context_mapper;
  }

  /**
   * Gets the Panelizer entity plugin.
   *
   * @param $entity_type_id
   *   The entity type id.
   *
   * @return \Drupal\panelizer\Plugin\PanelizerEntityInterface
   */
  protected function getEntityPlugin($entity_type_id) {
    return $this->panelizerEntityManager
      ->createInstance($entity_type_id, []);
  }

  /**
   * Load a Panels Display via an ID (Machine Name).
   *
   * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant|NULL
   *   The default Panels display with the given name if it exists; otherwise
   *   NULL.
   */
  public function getDefaultPanelsDisplayByMachineName($full_machine_name) {
    list($entity_type, $bundle, $view_mode, $machine_name) = explode('__', $full_machine_name);

    /** @var \Drupal\panelizer\Panelizer $panelizer */

    // @todo this $display_id looks all wrong to me since it's the name and view_mode.
    return $this
      ->getDefaultPanelsDisplay($machine_name, $entity_type, $bundle, $view_mode);
  }

  /**
   * {@inheritdoc}
   */
  public function getEntityViewDisplay($entity_type_id, $bundle, $view_mode) {

    // Check the existence and status of:
    // - the display for the view mode,
    // - the 'default' display.
    $candidate_ids = [];
    if ($view_mode != 'default') {
      $candidate_ids[] = $entity_type_id . '.' . $bundle . '.' . $view_mode;
    }
    $candidate_ids[] = $entity_type_id . '.' . $bundle . '.default';
    $results = \Drupal::entityQuery('entity_view_display')
      ->condition('id', $candidate_ids)
      ->condition('status', TRUE)
      ->execute();

    // Select the first valid candidate display, if any.
    $load_id = FALSE;
    foreach ($candidate_ids as $candidate_id) {
      if (isset($results[$candidate_id])) {
        $load_id = $candidate_id;
        break;
      }
    }

    // Use the selected display if any, or create a fresh runtime object.
    $storage = $this->entityTypeManager
      ->getStorage('entity_view_display');
    if ($load_id) {
      $display = $storage
        ->load($load_id);
    }
    else {
      $display = $storage
        ->create([
        'targetEntityType' => $entity_type_id,
        'bundle' => $bundle,
        'mode' => $view_mode,
        'status' => TRUE,
      ]);
    }

    // Let modules alter the display.
    $display_context = [
      'entity_type' => $entity_type_id,
      'bundle' => $bundle,
      'view_mode' => $view_mode,
    ];
    $this->moduleHandler
      ->alter('entity_view_display', $display, $display_context);
    return $display;
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelsDisplay(FieldableEntityInterface $entity, $view_mode, EntityViewDisplayInterface $display = NULL) {
    $settings = $this
      ->getPanelizerSettings($entity
      ->getEntityTypeId(), $entity
      ->bundle(), $view_mode, $display);
    if (($settings['custom'] || $settings['allow']) && isset($entity->panelizer) && $entity->panelizer
      ->first()) {

      /** @var \Drupal\Core\Field\FieldItemInterface[] $values */
      $values = [];
      foreach ($entity->panelizer as $item) {
        $values[$item->view_mode] = $item;
      }
      if (isset($values[$view_mode])) {
        $panelizer_item = $values[$view_mode];

        // Check for a customized display first and use that if present.
        if (!empty($panelizer_item->panels_display)) {

          // @todo: validate schema after https://www.drupal.org/node/2392057 is fixed.
          return $this->panelsManager
            ->importDisplay($panelizer_item->panels_display, FALSE);
        }

        // If not customized, use the specified default.
        if (!empty($panelizer_item->default)) {

          // If we're using this magic key use the settings default.
          if ($panelizer_item->default == '__bundle_default__') {
            $default = $settings['default'];
          }
          else {
            $default = $panelizer_item->default;

            // Ensure the default still exists and if not fallback sanely.
            $displays = $this
              ->getDefaultPanelsDisplays($entity
              ->getEntityTypeId(), $entity
              ->bundle(), $view_mode);
            if (!isset($displays[$default])) {
              $default = $settings['default'];
            }
          }
          $panels_display = $this
            ->getDefaultPanelsDisplay($default, $entity
            ->getEntityTypeId(), $entity
            ->bundle(), $view_mode, $display);
          $this
            ->setCacheTags($panels_display, $entity
            ->getEntityTypeId(), $entity
            ->bundle(), $view_mode, $display, $default, $settings);
          return $panels_display;
        }
      }
    }

    // If the field has no input to give us, use the settings default.
    $panels_display = $this
      ->getDefaultPanelsDisplay($settings['default'], $entity
      ->getEntityTypeId(), $entity
      ->bundle(), $view_mode, $display);
    $this
      ->setCacheTags($panels_display, $entity
      ->getEntityTypeId(), $entity
      ->bundle(), $view_mode, $display, $settings['default'], $settings);
    return $panels_display;
  }

  /**
   * Properly determine the cache tags for a display and set them.
   *
   * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
   *   The panels display variant.
   * @param string $entity_type_id
   *   The entity type id.
   * @param string $bundle
   *   The bundle.
   * @param string $view_mode
   *   The view mode.
   * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface|NULL $display
   *   If the caller already has the correct display, it can optionally be
   *   passed in here so the Panelizer service doesn't have to look it up;
   *   otherwise, this argument can be omitted.
   * @param $default
   *   The name of the panels display we are about to render.
   * @param array $settings
   *   The default panelizer settings for this EntityViewDisplay.
   */
  protected function setCacheTags(PanelsDisplayVariant $panels_display, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL, $default, array $settings) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    }
    $display_mode = $display ? $display
      ->getMode() : '';
    if ($default == $settings['default']) {
      $tags = [
        "{$panels_display->getStorageType()}:{$entity_type_id}:{$bundle}:{$display_mode}",
      ];
    }
    $tags[] = "{$panels_display->getStorageType()}:{$entity_type_id}:{$bundle}:{$display_mode}:{$default}";
    $panels_display
      ->addCacheTags($tags);
  }

  /**
   * {@inheritdoc}
   */
  public function setPanelsDisplay(FieldableEntityInterface $entity, $view_mode, $default, PanelsDisplayVariant $panels_display = NULL) {
    $settings = $this
      ->getPanelizerSettings($entity
      ->getEntityTypeId(), $entity
      ->bundle(), $view_mode);
    if (($settings['custom'] || $settings['allow']) && isset($entity->panelizer)) {
      $panelizer_item = NULL;

      /** @var \Drupal\Core\Field\FieldItemInterface $item */
      foreach ($entity->panelizer as $item) {
        if ($item->view_mode == $view_mode) {
          $panelizer_item = $item;
          break;
        }
      }
      if (!$panelizer_item) {
        $panelizer_item = $this->fieldTypeManager
          ->createFieldItem($entity->panelizer, count($entity->panelizer));
        $panelizer_item->view_mode = $view_mode;
      }

      // Note: We don't call $panels_display->setStorage() here because it will
      // be set internally by PanelizerFieldType::postSave() which will know
      // the real revision ID of the newly saved entity.
      $panelizer_item->panels_display = $panels_display ? $this->panelsManager
        ->exportDisplay($panels_display) : [];
      $panelizer_item->default = $default;

      // Create a new revision if possible.
      if ($entity instanceof RevisionableInterface && $entity
        ->getEntityType()
        ->isRevisionable()) {
        if ($entity
          ->isDefaultRevision()) {
          $entity
            ->setNewRevision(TRUE);
        }
      }

      // Updates the changed time of the entity, if necessary.
      if ($entity
        ->getEntityType()
        ->entityClassImplements(EntityChangedInterface::class)) {
        $request_time = \Drupal::time()
          ->getRequestTime();
        $entity
          ->setChangedTime($request_time);
      }
      $entity->panelizer[$panelizer_item
        ->getName()] = $panelizer_item;
      $entity
        ->save();
    }
    else {
      throw new PanelizerException("Custom overrides not enabled on this entity, bundle and view mode");
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultPanelsDisplays($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    }

    // Get a list of all the defaults.
    $display_config = $display
      ->getThirdPartySetting('panelizer', 'displays', []);
    $display_names = array_keys($display_config);
    if (empty($display_names)) {
      $display_names = [
        'default',
      ];
    }

    // Get each one individually.
    $panels_displays = [];
    foreach ($display_names as $name) {
      if ($panels_display = $this
        ->getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, $display)) {
        $panels_displays[$name] = $panels_display;
      }
    }
    return $panels_displays;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);

      // If we still don't find a display, then we won't find a Panelizer
      // default for sure.
      if (!$display) {
        return NULL;
      }
    }
    $config = $display
      ->getThirdPartySetting('panelizer', 'displays', []);
    if (!empty($config[$name])) {

      // Set a default just in case.
      $config[$name]['builder'] = empty($config[$name]['builder']) ? 'standard' : $config[$name]['builder'];

      // @todo: validate schema after https://www.drupal.org/node/2392057 is fixed.
      $panels_display = $this->panelsManager
        ->importDisplay($config[$name], FALSE);
    }
    else {
      return NULL;
    }

    // @todo: Should be set when written, not here!
    $storage_id_parts = [
      $entity_type_id,
      $bundle,
      $view_mode,
      $name,
    ];
    $panels_display
      ->setStorage('panelizer_default', implode(':', $storage_id_parts));
    return $panels_display;
  }

  /**
   * {@inheritdoc}
   */
  public function setDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, PanelsDisplayVariant $panels_display) {
    $display = $this
      ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    if (!$display) {
      throw new PanelizerException("Unable to find display for given entity type, bundle and view mode");
    }

    // Set this individual Panels display.
    $panels_displays = $display
      ->getThirdPartySetting('panelizer', 'displays', []);
    $panels_displays[$name] = $this->panelsManager
      ->exportDisplay($panels_display);
    $display
      ->setThirdPartySetting('panelizer', 'displays', $panels_displays);
    $display
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function getDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);

      // If we still don't find a display, then we won't find a Panelizer
      // default for sure.
      if (!$display) {
        return NULL;
      }
    }
    $config = $display
      ->getThirdPartySetting('panelizer', 'displays', []);
    if (!empty($config[$name]) && !empty($config[$name]['static_context'])) {
      return $this->contextMapper
        ->getContextValues($config[$name]['static_context']);
    }
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function setDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode, $contexts) {
    $display = $this
      ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    if (!$display) {
      throw new PanelizerException("Unable to find display for given entity type, bundle and view mode");
    }

    // Set this Panels display's static contexts.
    $panels_displays = $display
      ->getThirdPartySetting('panelizer', 'displays', []);
    $panels_displays[$name]['static_context'] = $contexts;
    $display
      ->setThirdPartySetting('panelizer', 'displays', $panels_displays);
    $display
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function isPanelized($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
    if (!$this
      ->getEntityPlugin($entity_type_id)) {
      return FALSE;
    }
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    }
    return $display
      ->getThirdPartySetting('panelizer', 'enable', FALSE);
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelizerSettings($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    }
    $settings = [
      'enable' => $this
        ->isPanelized($entity_type_id, $bundle, $view_mode, $display),
      'custom' => $display
        ->getThirdPartySetting('panelizer', 'custom', FALSE),
      'allow' => $display
        ->getThirdPartySetting('panelizer', 'allow', FALSE),
      'default' => $display
        ->getThirdPartySetting('panelizer', 'default', 'default'),
    ];

    // Make sure that the Panelizer field actually exists.
    if ($settings['custom']) {
      $fields = $this->entityFieldManager
        ->getFieldDefinitions($entity_type_id, $bundle);
      $settings['custom'] = isset($fields['panelizer']) && $fields['panelizer']
        ->getType() == 'panelizer';
    }
    return $settings;
  }

  /**
   * {@inheritdoc}
   */
  public function setPanelizerSettings($entity_type_id, $bundle, $view_mode, array $settings, EntityViewDisplayInterface $display = NULL) {
    if (!$display) {
      $display = $this
        ->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
    }
    $display
      ->setThirdPartySetting('panelizer', 'enable', !empty($settings['enable']));
    $display
      ->setThirdPartySetting('panelizer', 'custom', !empty($settings['enable']) && !empty($settings['custom']));
    $display
      ->setThirdPartySetting('panelizer', 'allow', !empty($settings['enable']) && !empty($settings['allow']));
    $display
      ->setThirdPartySetting('panelizer', 'default', $settings['default']);
    if (!empty($settings['enable'])) {

      // Set the default display.
      $displays = $display
        ->getThirdPartySetting('panelizer', 'displays', []);
      if (empty($displays['default'])) {

        /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_entity_plugin */
        $panelizer_entity_plugin = $this->panelizerEntityManager
          ->createInstance($display
          ->getTargetEntityTypeId(), []);
        $displays['default'] = $this->panelsManager
          ->exportDisplay($panelizer_entity_plugin
          ->getDefaultDisplay($display, $display
          ->getTargetBundle(), $display
          ->getMode()));
        $settings['default'] = "{$display->getTargetEntityTypeId()}__{$display->getTargetBundle()}__{$view_mode}__default";
        $display
          ->setThirdPartySetting('panelizer', 'displays', $displays);
      }

      // Make sure the field exists.
      if ($settings['custom'] || $settings['allow']) {
        $field_storage = $this->entityTypeManager
          ->getStorage('field_storage_config')
          ->load($entity_type_id . '.panelizer');
        if (!$field_storage) {
          $field_storage = $this->entityTypeManager
            ->getStorage('field_storage_config')
            ->create([
            'entity_type' => $entity_type_id,
            'field_name' => 'panelizer',
            'type' => 'panelizer',
            'cardinality' => -1,
            'settings' => [],
            'status' => TRUE,
          ]);
          $field_storage
            ->save();
        }
        $field = $this->entityTypeManager
          ->getStorage('field_config')
          ->load($entity_type_id . '.' . $bundle . '.panelizer');
        if (!$field) {
          $field = $this->entityTypeManager
            ->getStorage('field_config')
            ->create([
            'field_storage' => $field_storage,
            'bundle' => $bundle,
            'label' => $this
              ->t('Panelizer'),
            'settings' => [],
          ]);
          $field
            ->save();
        }
      }
    }
    $display
      ->save();
  }

  /**
   * Get a list of all the Panelizer operations.
   *
   * @return array
   *   Associative array of the human-readable operation names, keyed by the
   *   path.
   */
  protected function getOperations() {
    return [
      'content' => $this
        ->t('Content'),
      'layout' => $this
        ->t('Layout'),
      'revert' => $this
        ->t('Revert to default'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getPermissions() {
    $permissions = [];

    // Only look at entity types that have a corresponding Panelizer plugin.
    $entity_types = array_intersect_key($this->entityTypeManager
      ->getDefinitions(), $this->panelizerEntityManager
      ->getDefinitions());
    foreach ($entity_types as $entity_type_id => $entity_type) {
      $bundles = $this->entityTypeBundleInfo
        ->getBundleInfo($entity_type_id);
      foreach ($bundles as $bundle => $bundle_info) {
        $permissions["administer panelizer {$entity_type_id} {$bundle} defaults"] = [
          'title' => t('%entity_name %bundle_name: Administer Panelizer default panels, allowed content and settings.', [
            '%entity_name' => $entity_type
              ->getLabel(),
            '%bundle_name' => $bundle_info['label'],
          ]),
          'description' => t('Users with this permission can fully administer panelizer for this entity bundle.'),
        ];
        foreach ($this
          ->getOperations() as $path => $operation) {
          $permissions["administer panelizer {$entity_type_id} {$bundle} {$path}"] = [
            'title' => $this
              ->t('%entity_name %bundle_name: Administer Panelizer @operation', [
              '%entity_name' => $entity_type
                ->getLabel(),
              '%bundle_name' => $bundle_info['label'],
              '@operation' => $operation,
            ]),
          ];
        }
      }
    }
    ksort($permissions);
    return $permissions;
  }

  /**
   * Check permission for an individual operation only.
   *
   * Doesn't check any of the baseline permissions that you need along with
   * the operation permission.
   *
   * @param string $op
   *   The operation.
   * @param string $entity_type_id
   *   The entity type id.
   * @param string $bundle
   *   The bundle.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user account.
   *
   * @return bool
   *   TRUE if the user has permission; FALSE otherwise.
   */
  protected function hasOperationPermission($op, $entity_type_id, $bundle, AccountInterface $account) {
    switch ($op) {
      case 'change content':
        return $account
          ->hasPermission("administer panelizer {$entity_type_id} {$bundle} content");
      case 'change layout':
        return $account
          ->hasPermission("administer panelizer {$entity_type_id} {$bundle} layout");
      case 'revert to default':
        return $account
          ->hasPermission("administer panelizer {$entity_type_id} {$bundle} revert");
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function hasEntityPermission($op, EntityInterface $entity, $view_mode, AccountInterface $account = NULL) {
    if (!$account) {
      $account = $this->currentUser
        ->getAccount();
    }

    // Must be able to edit the entity.
    if (!$entity
      ->access('update', $account)) {
      return FALSE;
    }

    // Must have overrides enabled.
    $panelizer_settings = $this
      ->getPanelizerSettings($entity
      ->getEntityTypeId(), $entity
      ->bundle(), $view_mode);
    if (empty($panelizer_settings['custom'])) {
      return FALSE;
    }

    // Check admin permission.
    if ($account
      ->hasPermission('administer panelizer')) {
      return TRUE;
    }

    // @todo: check field access too!
    // if ($op == 'revert to default') {
    //   // We already have enough permissions at this point.
    //   return TRUE;
    // }
    return $this
      ->hasOperationPermission($op, $entity
      ->getEntityTypeId(), $entity
      ->bundle(), $account);
  }

  /**
   * {@inheritdoc}
   */
  public function hasDefaultPermission($op, $entity_type_id, $bundle, $view_mode, $default, AccountInterface $account = NULL) {
    if (!$this
      ->isPanelized($entity_type_id, $bundle, $view_mode)) {
      return FALSE;
    }
    if (!$account) {
      $account = $this->currentUser
        ->getAccount();
    }

    // Check admin permissions.
    if ($account
      ->hasPermission('administer panelizer')) {
      return TRUE;
    }
    if ($account
      ->hasPermission("administer panelizer {$entity_type_id} {$bundle} defaults")) {
      return TRUE;
    }
    return $this
      ->hasOperationPermission($op, $entity_type_id, $bundle, $account);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Panelizer::$contextMapper protected property The context mapper.
Panelizer::$currentUser protected property The current user service.
Panelizer::$entityFieldManager protected property The entity field manager.
Panelizer::$entityTypeBundleInfo protected property The entity type bundle info manager.
Panelizer::$entityTypeManager protected property The entity type manager.
Panelizer::$fieldTypeManager protected property The field type manager.
Panelizer::$moduleHandler protected property The module handler.
Panelizer::$panelizerEntityManager protected property The Panelizer entity manager.
Panelizer::$panelsManager protected property The Panels display manager.
Panelizer::getDefaultPanelsDisplay public function Gets one default Panels display for an entity type, bundle and view mode. Overrides PanelizerInterface::getDefaultPanelsDisplay
Panelizer::getDefaultPanelsDisplayByMachineName public function Load a Panels Display via an ID (Machine Name).
Panelizer::getDefaultPanelsDisplays public function Gets the default Panels displays for an entity type, bundle and view mode. Overrides PanelizerInterface::getDefaultPanelsDisplays
Panelizer::getDisplayStaticContexts public function Overrides PanelizerInterface::getDisplayStaticContexts
Panelizer::getEntityPlugin protected function Gets the Panelizer entity plugin.
Panelizer::getEntityViewDisplay public function Gets the entity view display for the entity type, bundle and view mode. Overrides PanelizerInterface::getEntityViewDisplay
Panelizer::getOperations protected function Get a list of all the Panelizer operations.
Panelizer::getPanelizerSettings public function Get the Panelizer settings for an entity type, bundle and view mode. Overrides PanelizerInterface::getPanelizerSettings
Panelizer::getPanelsDisplay public function Gets the Panels display for a given entity and view mode. Overrides PanelizerInterface::getPanelsDisplay
Panelizer::getPermissions public function Get permissions for all panelized entity types and bundles. Overrides PanelizerInterface::getPermissions
Panelizer::hasDefaultPermission public function Checks if a user has permission to perform an operation on a default. Overrides PanelizerInterface::hasDefaultPermission
Panelizer::hasEntityPermission public function Checks if a user has permission to perform an operation on an entity. Overrides PanelizerInterface::hasEntityPermission
Panelizer::hasOperationPermission protected function Check permission for an individual operation only.
Panelizer::isPanelized public function Checks if the given entity type, bundle and view mode are panelized. Overrides PanelizerInterface::isPanelized
Panelizer::setCacheTags protected function Properly determine the cache tags for a display and set them.
Panelizer::setDefaultPanelsDisplay public function Overrides PanelizerInterface::setDefaultPanelsDisplay
Panelizer::setDisplayStaticContexts public function Overrides PanelizerInterface::setDisplayStaticContexts
Panelizer::setPanelizerSettings public function Overrides PanelizerInterface::setPanelizerSettings
Panelizer::setPanelsDisplay public function Sets the Panels display for a given entity and view mode. Overrides PanelizerInterface::setPanelsDisplay
Panelizer::__construct public function Constructs a Panelizer.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.