Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MediaHooks.php

function MediaHooks::entityAccess

Implements hook_entity_access().

File

core/modules/media/src/Hook/MediaHooks.php, line 104

Class

MediaHooks
Hook implementations for media.

Namespace

Drupal\media\Hook

Code

public function entityAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($operation === 'delete' && $entity instanceof FieldConfigInterface && $entity->getTargetEntityTypeId() === 'media') {
        
        /** @var \Drupal\media\MediaTypeInterface $media_type */
        $media_type = \Drupal::entityTypeManager()->getStorage('media_type')
            ->load($entity->getTargetBundle());
        return AccessResult::forbiddenIf($entity->id() === 'media.' . $media_type->id() . '.' . $media_type->getSource()
            ->getConfiguration()['source_field']);
    }
    return AccessResult::neutral();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal