getOpenerParameters example

return $test_data;
  }

  /** * @covers ::getOpenerParameters */
  public function testOpenerParameters() {
    $state = MediaLibraryState::create('test', ['file'], 'file', -1, [
      'foo' => 'baz',
    ]);
    $this->assertSame(['foo' => 'baz']$state->getOpenerParameters());
  }

  /** * Tests that hash is unaffected by allowed media type order. */
  public function testHashUnaffectedByMediaTypeOrder() {
    $state1 = MediaLibraryState::create('test', ['file', 'image'], 'image', 2);
    $state2 = MediaLibraryState::create('test', ['image', 'file'], 'image', 2);
    $this->assertSame($state1->getHash()$state2->getHash());
  }

  
$access_result = $ui_builder->checkAccess($this->createUser()$state);
    $this->assertAccess($access_result, FALSE, NULL, []['url.query_args']);

    $neutral_entity = EntityTest::create([
      'type' => 'test',
      // This label will result in neutral access.       // @see \Drupal\entity_test\EntityTestAccessControlHandler::checkAccess()       'name' => $this->randomString(),
    ]);
    $neutral_entity->save();

    $parameters = $state->getOpenerParameters();
    $parameters['entity_id'] = $neutral_entity->id();
    $state = MediaLibraryState::create(
      $state->getOpenerId(),
      $state->getAllowedTypeIds(),
      $state->getSelectedTypeId(),
      $state->getAvailableSlots(),
      $parameters
    );

    $access_result = $ui_builder->checkAccess($this->createUser()$state);
    $this->assertTrue($access_result->isNeutral());
    

  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /** * {@inheritdoc} */
  public function checkAccess(MediaLibraryState $state, AccountInterface $account) {
    $parameters = $state->getOpenerParameters() + ['entity_id' => NULL];

    // Forbid access if any of the required parameters are missing.     foreach (['entity_type_id', 'bundle', 'field_name'] as $key) {
      if (empty($parameters[$key])) {
        return AccessResult::forbidden("$key parameter is missing.")->addCacheableDependency($state);
      }
    }

    $entity_type_id = $parameters['entity_type_id'];
    $bundle = $parameters['bundle'];
    $field_name = $parameters['field_name'];

    

  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->filterStorage = $entity_type_manager->getStorage('filter_format');
    $this->mediaStorage = $entity_type_manager->getStorage('media');
  }

  /** * {@inheritdoc} */
  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));
  }

  

  public function getHash() {
    // Create a hash from the required state parameters and the serialized     // optional opener-specific parameters. Sort the allowed types and     // opener parameters so that differences in order do not result in     // different hashes.     $allowed_media_type_ids = array_values($this->getAllowedTypeIds());
    sort($allowed_media_type_ids);
    $opener_parameters = $this->getOpenerParameters();
    ksort($opener_parameters);
    $hash = implode(':', [
      $this->getOpenerId(),
      implode(':', $allowed_media_type_ids),
      $this->getSelectedTypeId(),
      $this->getAvailableSlots(),
      serialize($opener_parameters),
    ]);

    return Crypt::hmacBase64($hash, \Drupal::service('private_key')->get() . Settings::getHashSalt());
  }

  
'#theme' => 'links__media_library_menu',
      '#links' => [],
      '#attributes' => [
        'class' => ['js-media-library-menu'],
      ],
    ];

    $allowed_types = $this->entityTypeManager->getStorage('media_type')->loadMultiple($allowed_type_ids);

    $selected_type_id = $state->getSelectedTypeId();
    foreach ($allowed_types as $allowed_type_id => $allowed_type) {
      $link_state = MediaLibraryState::create($state->getOpenerId()$state->getAllowedTypeIds()$allowed_type_id$state->getAvailableSlots()$state->getOpenerParameters());
      // Add the 'media_library_content' parameter so the response will contain       // only the updated content for the tab.       // @see self::buildUi()       $link_state->set('media_library_content', 1);

      $title = $allowed_type->label();
      $display_title = [
        '#markup' => $this->t('<span class="visually-hidden">Show </span>@title<span class="visually-hidden"> media</span>', ['@title' => $title]),
      ];
      if ($allowed_type_id === $selected_type_id) {
        $display_title = [
          
Home | Imprint | This part of the site doesn't use cookies.