function CKEditor5MediaController::access

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php \Drupal\ckeditor5\Controller\CKEditor5MediaController::access()
  2. 10 core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php \Drupal\ckeditor5\Controller\CKEditor5MediaController::access()

Additional access check for ::isMediaImage().

This grants access if media embed filter is enabled on the filter format and user has access to view the media entity.

Note that access to the filter format is not checked here because the route is configured to check entity access to the filter format.

Parameters

\Drupal\editor\Entity\Editor $editor: The text editor.

Return value

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

Throws

\Symfony\Component\HttpKernel\Exception\BadRequestHttpException Thrown when no media UUID is provided.

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown when no media with the provided UUID exists.

1 string reference to 'CKEditor5MediaController::access'
ckeditor5.routing.yml in core/modules/ckeditor5/ckeditor5.routing.yml
core/modules/ckeditor5/ckeditor5.routing.yml

File

core/modules/ckeditor5/src/Controller/CKEditor5MediaController.php, line 139

Class

CKEditor5MediaController
Provides an API for checking if a media entity has image field.

Namespace

Drupal\ckeditor5\Controller

Code

public function access(Editor $editor) : AccessResultInterface {
    if ($editor->getEditor() !== 'ckeditor5') {
        return AccessResult::forbidden();
    }
    // @todo add current request as an argument after
    // https://www.drupal.org/project/drupal/issues/2786941 has been resolved.
    $request = $this->requestStack
        ->getCurrentRequest();
    $uuid = $request->query
        ->get('uuid');
    if (!$uuid || !Uuid::isValid($uuid)) {
        throw new BadRequestHttpException();
    }
    $media = $this->entityRepository
        ->loadEntityByUuid('media', $uuid);
    if (!$media) {
        throw new NotFoundHttpException();
    }
    $filters = $editor->getFilterFormat()
        ->filters();
    return AccessResult::allowedIf($filters->has('media_embed') && $filters->get('media_embed')->status)
        ->andIf($media->access('view', $this->currentUser, TRUE))
        ->addCacheableDependency($editor->getFilterFormat());
}

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