function MediaLibraryEditorOpener::checkAccess

Same name in other branches
  1. 9 core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::checkAccess()
  2. 8.9.x core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::checkAccess()
  3. 11.x core/modules/media_library/src/MediaLibraryEditorOpener.php \Drupal\media_library\MediaLibraryEditorOpener::checkAccess()

Overrides MediaLibraryOpenerInterface::checkAccess

File

core/modules/media_library/src/MediaLibraryEditorOpener.php, line 47

Class

MediaLibraryEditorOpener
The media library opener for text editors.

Namespace

Drupal\media_library

Code

public function checkAccess(MediaLibraryState $state, AccountInterface $account) {
    $filter_format_id = $state->getOpenerParameters()['filter_format_id'];
    $filter_format = $this->filterStorage
        ->load($filter_format_id);
    if (empty($filter_format)) {
        return AccessResult::forbidden()->addCacheTags([
            'filter_format_list',
        ])
            ->setReason("The text format '{$filter_format_id}' could not be loaded.");
    }
    $filters = $filter_format->filters();
    return $filter_format->access('use', $account, TRUE)
        ->andIf(AccessResult::allowedIf($filters->has('media_embed') && $filters->get('media_embed')->status === TRUE));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.