summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/media_library/src/MediaLibraryOpenerInterface.php
blob: 261ef4c161fcab0d6e181b28350af0bb243645f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

namespace Drupal\media_library;

use Drupal\Core\Session\AccountInterface;

/**
 * Defines an interface for media library openers.
 *
 * Media library opener services allow modules to check access to the media
 * library selection dialog and respond to selections. Example use cases that
 * require different handling:
 * - when used in an entity reference field widget;
 * - when used in a text editor.
 *
 * Openers that require additional parameters or metadata should retrieve them
 * from the MediaLibraryState object.
 *
 * @see \Drupal\media_library\MediaLibraryState
 * @see \Drupal\media_library\MediaLibraryState::getOpenerParameters()
 */
interface MediaLibraryOpenerInterface {

  /**
   * Checks media library access.
   *
   * @param \Drupal\media_library\MediaLibraryState $state
   *   The media library.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user for which to check access.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   *
   * @see https://www.drupal.org/project/drupal/issues/3038254
   */
  public function checkAccess(MediaLibraryState $state, AccountInterface $account);

  /**
   * Generates a response after selecting media items in the media library.
   *
   * @param \Drupal\media_library\MediaLibraryState $state
   *   The state the media library was in at the time of selection, allowing the
   *   response to be customized based on that state.
   * @param int[] $selected_ids
   *   The IDs of the selected media items.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   The response to update the page after selecting media.
   */
  public function getSelectionResponse(MediaLibraryState $state, array $selected_ids);

}