You are here

public function PanelizerDefaultsDisplayAccess::isNotDefaultDisplay in Panelizer 8.4

Same name and namespace in other branches
  1. 8.5 src/Access/PanelizerDefaultsDisplayAccess.php \Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess::isNotDefaultDisplay()
  2. 8.3 src/Access/PanelizerDefaultsDisplayAccess.php \Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess::isNotDefaultDisplay()

Custom access checker for determining the default display of the bundle.

Parameters

string $machine_name: The machine name of the default display.

Return value

\Drupal\Core\Access\AccessResult

1 string reference to 'PanelizerDefaultsDisplayAccess::isNotDefaultDisplay'
panelizer.routing.yml in ./panelizer.routing.yml
panelizer.routing.yml

File

src/Access/PanelizerDefaultsDisplayAccess.php, line 20

Class

PanelizerDefaultsDisplayAccess
Provides a custom access checking mechanism for default displays.

Namespace

Drupal\panelizer\Access

Code

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}",
  ]);
}