interface SelectionInterface

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.

Hierarchy

Expanded class hierarchy of SelectionInterface

All classes that implement SelectionInterface

2 files declare their use of SelectionInterface
SelectionBase.php in drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php
Contains \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase.
ViewsSelection.php in drupal/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php
Contains \Drupal\views\Plugin\entity_reference\selection\ViewsSelection.

File

drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/Selection/SelectionInterface.php, line 20
Contains \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface.

Namespace

Drupal\entity_reference\Plugin\Type\Selection
View source
interface SelectionInterface {

  /**
   * Returns a list of referencable entities.
   *
   * @return array
   *   An array of referencable entities. Keys are entity IDs and
   *   values are (safe HTML) labels to be displayed to the user.
   */
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);

  /**
   * Counts entities that are referencable by a given field.
   *
   * @return int
   *   The number of referencable entities.
   */
  public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS');

  /**
   * Validates that entities can be referenced by this field.
   *
   * @return array
   *   An array of valid entity IDs.
   */
  public function validateReferencableEntities(array $ids);

  /**
   * 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);

}

Members

Namesort descending Modifiers Type Description Overrides
SelectionInterface::countReferencableEntities public function Counts entities that are referencable by a given field. 3
SelectionInterface::entityQueryAlter public function Allows the selection to alter the SelectQuery generated by EntityFieldQuery. 3
SelectionInterface::getReferencableEntities public function Returns a list of referencable entities. 3
SelectionInterface::settingsForm public static function Generates the settings form for this selection. 3
SelectionInterface::validateAutocompleteInput public function Validates input from an autocomplete widget that has no ID. 3
SelectionInterface::validateReferencableEntities public function Validates that entities can be referenced by this field. 3