public function LinkitMediaLibraryEditorOpener::checkAccess in Linkit Media Library 1.0.x
Checks media library access.
Parameters
\Drupal\media_library\MediaLibraryState $state: The media library.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides MediaLibraryOpenerInterface::checkAccess
See also
https://www.drupal.org/project/drupal/issues/3038254
File
- src/
LinkitMediaLibraryEditorOpener.php, line 48
Class
- LinkitMediaLibraryEditorOpener
- The media library opener for text editors.
Namespace
Drupal\linkit_media_libraryCode
public function checkAccess(MediaLibraryState $state, AccountInterface $account) {
$filter_format_id = $state
->getOpenerParameters()['filter_format_id'];
/** @var \Drupal\filter\FilterFormatInterface $filter_format */
$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.");
}
/** @var Drupal\filter\FilterPluginCollection $filters */
$filters = $filter_format
->filters();
return $filter_format
->access('use', $account, TRUE)
->andIf(AccessResult::allowedIf($filters
->has('linkit') && $filters
->get('linkit')->status === TRUE));
}