You are here

class ViewModeAccessCheck in Panelizer 8.3

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

An access check as an adapter around field_ui's custom access check.

Hierarchy

Expanded class hierarchy of ViewModeAccessCheck

1 string reference to 'ViewModeAccessCheck'
panelizer.services.yml in ./panelizer.services.yml
panelizer.services.yml
1 service uses ViewModeAccessCheck
access_check.panelizer.view_mode in ./panelizer.services.yml
Drupal\panelizer\Access\ViewModeAccessCheck

File

src/Access/ViewModeAccessCheck.php, line 14

Namespace

Drupal\panelizer\Access
View source
class ViewModeAccessCheck implements AccessInterface {

  /**
   * The decorated ViewModeAccessCheck from field_ui.
   *
   * @var \Drupal\field_ui\Access\ViewModeAccessCheck
   */
  protected $accessCheck;

  /**
   * ViewModeAccessCheck constructor.
   *
   * @param \Drupal\field_ui\Access\ViewModeAccessCheck $access_check
   */
  public function __construct(FieldUIViewModeAccessCheck $access_check) {
    $this->accessCheck = $access_check;
  }

  /**
   * Adapt the panelizer defaults access check to correspond to field ui.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   The original route definition.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route matched.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The current user's account.
   * @param string $machine_name
   *   The machine name of the panelizer default.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   * @throws \Exception
   */
  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $machine_name) {
    $parts = explode('__', $machine_name);
    if (count($parts) != 4) {
      throw new \Exception('The provided machine_name is not well formed.');
    }
    list($entity_type_id, $bundle, $view_mode) = $parts;
    $defaults = [
      'entity_type_id' => $entity_type_id,
    ] + $route
      ->getDefaults();
    $route
      ->setDefaults($defaults);
    $route
      ->setRequirement('_field_ui_view_mode_access', 'administer ' . $entity_type_id . ' display');
    return $this->accessCheck
      ->access($route, $route_match, $account, $view_mode, $bundle);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewModeAccessCheck::$accessCheck protected property The decorated ViewModeAccessCheck from field_ui.
ViewModeAccessCheck::access public function Adapt the panelizer defaults access check to correspond to field ui.
ViewModeAccessCheck::__construct public function ViewModeAccessCheck constructor.