Projet

Général

Profil

Paste
Télécharger (3,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / entityreference / plugins / selection / abstract.inc @ a2bb1a14

1
<?php
2

    
3
/**
4
 * @file
5
 * Abstraction of the selection logic of an entity reference field.
6
 *
7
 * Implementations that wish to provide an implementation of this should
8
 * register it using CTools' plugin system.
9
 */
10
interface EntityReference_SelectionHandler {
11
  /**
12
   * Factory function: create a new instance of this handler for a given field.
13
   *
14
   * @param $field
15
   *   A field datastructure.
16
   * @return EntityReferenceHandler
17
   */
18
  public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL);
19

    
20
  /**
21
   * Return a list of referencable entities.
22
   *
23
   * @return
24
   *   An array of referencable entities, which keys are entity ids and
25
   *   values (safe HTML) labels to be displayed to the user.
26
   */
27
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);
28

    
29
  /**
30
   * Count entities that are referencable by a given field.
31
   */
32
  public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS');
33

    
34
  /**
35
   * Validate that entities can be referenced by this field.
36
   *
37
   * @return
38
   *   An array of entity ids that are valid.
39
   */
40
  public function validateReferencableEntities(array $ids);
41

    
42
  /**
43
   * Validate Input from autocomplete widget that has no Id.
44
   *
45
   * @see _entityreference_autocomplete_validate()
46
   *
47
   * @param $input
48
   * 	 Single string from autocomplete widget.
49
   * @param $element
50
   *   The form element to set a form error.
51
   * @return
52
   *   Value of a matching entity id, or NULL if none.
53
   */
54
  public function validateAutocompleteInput($input, &$element, &$form_state, $form);
55

    
56
  /**
57
   * Give the handler a chance to alter the SelectQuery generated by EntityFieldQuery.
58
   */
59
  public function entityFieldQueryAlter(SelectQueryInterface $query);
60

    
61
  /**
62
   * Return the label of a given entity.
63
   */
64
  public function getLabel($entity);
65

    
66
  /**
67
   * Generate a settings form for this handler.
68
   */
69
  public static function settingsForm($field, $instance);
70
}
71

    
72
/**
73
 * A null implementation of EntityReference_SelectionHandler.
74
 */
75
class EntityReference_SelectionHandler_Broken implements EntityReference_SelectionHandler {
76
  public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
77
    return new EntityReference_SelectionHandler_Broken($field, $instance, $entity_type, $entity);
78
  }
79

    
80
  protected function __construct($field, $instance) {
81
    $this->field = $field;
82
    $this->instance = $instance;
83
  }
84

    
85
  public static function settingsForm($field, $instance) {
86
    $form['selection_handler'] = array(
87
      '#markup' => t('The selected selection handler is broken.'),
88
    );
89
    return $form;
90
  }
91

    
92
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
93
    return array();
94
  }
95

    
96
  public function countReferencableEntities($match = NULL, $match_operator = 'CONTAINS') {
97
    return 0;
98
  }
99

    
100
  public function validateReferencableEntities(array $ids) {
101
    return array();
102
  }
103

    
104
  public function validateAutocompleteInput($input, &$element, &$form_state, $form) {
105
    return NULL;
106
  }
107

    
108
  public function entityFieldQueryAlter(SelectQueryInterface $query) {}
109

    
110
  public function getLabel($entity) {
111
    return '';
112
  }
113
}