ViewModeAccessCheck.php in Panelizer 8.4
File
src/Access/ViewModeAccessCheck.php
View source
<?php
namespace Drupal\panelizer\Access;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field_ui\Access\ViewModeAccessCheck as FieldUIViewModeAccessCheck;
use Symfony\Component\Routing\Route;
class ViewModeAccessCheck implements AccessInterface {
protected $accessCheck;
public function __construct(FieldUIViewModeAccessCheck $access_check) {
$this->accessCheck = $access_check;
}
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);
}
}