SelectionInterface.php 2.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php

/**
 * @file
 * Contains \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface.
 */

namespace Drupal\entity_reference\Plugin\Type\Selection;

use Drupal\Core\Database\Query\SelectInterface;

/**
 * Interface definition for Entity Reference selection plugins.
 *
 * This interface details the methods that most plugin implementations will want
 * to override. See \Drupal\field\Plugin\Type\Selection\SelectionBaseInterface
 * for base wrapping methods that should most likely be inherited directly from
 * Drupal\entity_reference\Plugin\Type\Selection\SelectionBase.
 */
interface SelectionInterface {

  /**
23
   * Returns a list of referenceable entities.
24 25
   *
   * @return array
26
   *   An array of referenceable entities. Keys are entity IDs and
27 28
   *   values are (safe HTML) labels to be displayed to the user.
   */
29
  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);
30 31

  /**
32
   * Counts entities that are referenceable by a given field.
33 34
   *
   * @return int
35
   *   The number of referenceable entities.
36
   */
37
  public function countReferenceableEntities($match = NULL, $match_operator = 'CONTAINS');
38 39 40 41 42 43 44

  /**
   * Validates that entities can be referenced by this field.
   *
   * @return array
   *   An array of valid entity IDs.
   */
45
  public function validateReferenceableEntities(array $ids);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

  /**
   * Validates input from an autocomplete widget that has no ID.
   *
   * @param string $input
   *   Single string from autocomplete widget.
   * @param array $element
   *   The form element to set a form error.
   * @param boolean $strict
   *   Whether to trigger a form error if an element from $input (eg. an entity)
   *   is not found. Defaults to TRUE.
   *
   * @return integer|null
   *   Value of a matching entity ID, or NULL if none.
   *
   * @see \Drupal\entity_reference\Plugin\field\widget::elementValidate()
   */
  public function validateAutocompleteInput($input, &$element, &$form_state, $form, $strict = TRUE);

  /**
   * Allows the selection to alter the SelectQuery generated by EntityFieldQuery.
   *
   * @param \Drupal\Core\Database\Query\SelectInterface $query
   *   A Select Query object.
   */
  public function entityQueryAlter(SelectInterface $query);

  /**
   * Generates the settings form for this selection.
   *
   * @param array $field
   *   A field data structure.
   * @param array $instance
   *   A field instance data structure.
   *
   * @return array
   *   A Form API array.
   */
  public static function settingsForm(&$field, &$instance);
}