Projet

Général

Profil

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

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

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
   *   A nested array of entities, the first level is keyed by the
25
   *   entity bundle, which contains an array of entity labels (safe HTML),
26
   *   keyed by the entity ID.
27
   */
28
  public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);
29

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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