You are here

class PanelizerDefaultsDisplayAccess in Panelizer 8.3

Same name and namespace in other branches
  1. 8.5 src/Access/PanelizerDefaultsDisplayAccess.php \Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess
  2. 8.4 src/Access/PanelizerDefaultsDisplayAccess.php \Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess

Provides a custom access checking mechanism for default displays.

Hierarchy

Expanded class hierarchy of PanelizerDefaultsDisplayAccess

File

src/Access/PanelizerDefaultsDisplayAccess.php, line 10

Namespace

Drupal\panelizer\Access
View source
class PanelizerDefaultsDisplayAccess {

  /**
   * Custom access checker for determining the default display of the bundle.
   *
   * @param string $machine_name
   *   The machine name of the default display.
   *
   * @return \Drupal\Core\Access\AccessResult
   */
  public function isNotDefaultDisplay($machine_name) {
    list($entity_type, $bundle, $view_mode, $default) = explode('__', $machine_name);

    /** @var \Drupal\panelizer\Panelizer $panelizer */
    $panelizer = \Drupal::service('panelizer');
    $settings = $panelizer
      ->getPanelizerSettings($entity_type, $bundle, $view_mode);
    if ($settings['default'] != $default) {
      $access = AccessResult::allowed();
    }
    else {
      $access = AccessResult::forbidden();
    }
    return $access
      ->addCacheTags([
      "panelizer_default:{$entity_type}:{$bundle}:{$view_mode}",
      "panelizer_default:{$entity_type}:{$bundle}:{$view_mode}:{$default}",
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PanelizerDefaultsDisplayAccess::isNotDefaultDisplay public function Custom access checker for determining the default display of the bundle.