media_library_test.module

Same filename in other branches
  1. 8.9.x core/modules/media_library/tests/modules/media_library_test/media_library_test.module
  2. 10 core/modules/media_library/tests/modules/media_library_test/media_library_test.module
  3. 11.x core/modules/media_library/tests/modules/media_library_test/media_library_test.module

Contains hook implementations for the media_library_test module.

File

core/modules/media_library/tests/modules/media_library_test/media_library_test.module

View source
<?php


/**
 * @file
 * Contains hook implementations for the media_library_test module.
 */
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\media_library_test\Form\TestNodeFormOverride;

/**
 * Implements hook_ENTITY_TYPE_create_access().
 */
function media_library_test_media_create_access(AccountInterface $account, array $context, $entity_bundle) {
    if (isset($context['media_library_state'])) {
        
        /** @var \Drupal\media_library\MediaLibraryState $state */
        $state = $context['media_library_state'];
        return AccessResult::forbiddenIf($state->getSelectedTypeId() === 'deny_access');
    }
    return AccessResult::neutral();
}

/**
 * Implements hook_entity_field_access().
 */
function media_library_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
    $deny_fields = \Drupal::state()->get('media_library_test_entity_field_access_deny_fields', []);
    // Always deny the field_media_no_access field.
    $deny_fields[] = 'field_media_no_access';
    return AccessResult::forbiddenIf(in_array($field_definition->getName(), $deny_fields, TRUE), 'Field access denied by test module');
}

/**
 * Implements hook_entity_type_alter().
 */
function media_library_test_entity_type_alter(array &$entity_types) {
    if (isset($entity_types['node'])) {
        $entity_types['node']->setFormClass('default', TestNodeFormOverride::class);
        $entity_types['node']->setFormClass('edit', TestNodeFormOverride::class);
    }
}

/**
 * Implements hook_field_widget_info_alter().
 */
function media_library_test_field_widget_info_alter(array &$info) {
    $info['media_library_widget']['field_types'][] = 'entity_reference_subclass';
}

Functions

Title Deprecated Summary
media_library_test_entity_field_access Implements hook_entity_field_access().
media_library_test_entity_type_alter Implements hook_entity_type_alter().
media_library_test_field_widget_info_alter Implements hook_field_widget_info_alter().
media_library_test_media_create_access Implements hook_ENTITY_TYPE_create_access().

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