You are here

protected function EmbedButtonEditorAccessCheck::checkButtonEditorAccess in Embed 8

Checks if the embed button is enabled in an editor configuration.

Parameters

\Drupal\embed\EmbedButtonInterface $embed_button: The embed button entity to check.

\Drupal\editor\EditorInterface $editor: The editor entity to check.

Return value

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

Throws

\Symfony\Component\HttpKernel\Exception\HttpException When the received Text Editor entity does not use CKEditor. This is currently only capable of detecting buttons used by CKEditor.

1 call to EmbedButtonEditorAccessCheck::checkButtonEditorAccess()
EmbedButtonEditorAccessCheck::access in src/Access/EmbedButtonEditorAccessCheck.php
Checks whether the embed button is enabled for the given text editor.

File

src/Access/EmbedButtonEditorAccessCheck.php, line 80

Class

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

Namespace

Drupal\embed\Access

Code

protected function checkButtonEditorAccess(EmbedButtonInterface $embed_button, EditorInterface $editor) {
  if ($editor
    ->getEditor() !== 'ckeditor') {
    throw new HttpException(500, 'Currently, only CKEditor is supported.');
  }
  $has_button = FALSE;
  $settings = $editor
    ->getSettings();
  foreach ($settings['toolbar']['rows'] as $row) {
    foreach ($row as $group) {
      if (in_array($embed_button
        ->id(), $group['items'])) {
        $has_button = TRUE;
        break 2;
      }
    }
  }
  return AccessResult::allowedIf($has_button)
    ->addCacheableDependency($embed_button)
    ->addCacheableDependency($editor);
}