You are here

public function EmbedButtonEditorAccessCheck::access in Embed 8

Checks whether the embed button is enabled for the given text editor.

Returns allowed if the editor toolbar contains the embed button or neutral otherwise.


pattern: '/foo/{editor}/{embed_button}'
requirements:
  _embed_button_editor_access: 'TRUE'

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

src/Access/EmbedButtonEditorAccessCheck.php, line 38

Class

EmbedButtonEditorAccessCheck
Routing requirement access check for embed buttons and text editors.

Namespace

Drupal\embed\Access

Code

public function access(RouteMatchInterface $route_match, AccountInterface $account) {
  $parameters = $route_match
    ->getParameters();
  $access_result = AccessResult::allowedIf($parameters
    ->has('editor') && $parameters
    ->has('embed_button'))
    ->addCacheContexts([
    'route',
  ]);
  if ($access_result
    ->isAllowed()) {
    $editor = $parameters
      ->get('editor');
    $embed_button = $parameters
      ->get('embed_button');
    if ($editor instanceof EditorInterface && $embed_button instanceof EmbedButtonInterface) {
      return $access_result
        ->andIf($editor
        ->getFilterFormat()
        ->access('use', $account, TRUE))
        ->andIf($this
        ->checkButtonEditorAccess($embed_button, $editor));
    }
  }

  // No opinion, so other access checks should decide if access should be
  // allowed or not.
  return $access_result;
}