class ViewModeAccessCheck in Panelizer 8.3
Same name and namespace in other branches
- 8.5 src/Access/ViewModeAccessCheck.php \Drupal\panelizer\Access\ViewModeAccessCheck
- 8.4 src/Access/ViewModeAccessCheck.php \Drupal\panelizer\Access\ViewModeAccessCheck
An access check as an adapter around field_ui's custom access check.
Hierarchy
- class \Drupal\panelizer\Access\ViewModeAccessCheck implements AccessInterface
Expanded class hierarchy of ViewModeAccessCheck
1 string reference to 'ViewModeAccessCheck'
1 service uses ViewModeAccessCheck
File
- src/
Access/ ViewModeAccessCheck.php, line 14
Namespace
Drupal\panelizer\AccessView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ViewModeAccessCheck:: |
protected | property | The decorated ViewModeAccessCheck from field_ui. | |
ViewModeAccessCheck:: |
public | function | Adapt the panelizer defaults access check to correspond to field ui. | |
ViewModeAccessCheck:: |
public | function | ViewModeAccessCheck constructor. |