1 | <?php |
||
33 | class EntityBrowserElement extends FormElement { |
||
34 | |||
35 | /** |
||
36 | * Indicating an entity browser can return an unlimited number of values. |
||
37 | * |
||
38 | * Note: When entity browser is used in Fields, cardinality is directly |
||
39 | * propagated from Field settings, that's why this constant should be equal to |
||
40 | * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED. |
||
41 | */ |
||
42 | const CARDINALITY_UNLIMITED = -1; |
||
43 | |||
44 | /** |
||
45 | * Selection from entity browser will be appended to existing list. |
||
46 | * |
||
47 | * When this selection mode is used, then entity browser will not be |
||
48 | * populated with existing selection. Preselected list will be empty. |
||
49 | * |
||
50 | * Note: This option is also used by "js/entity_browser.common.js". |
||
51 | */ |
||
52 | const SELECTION_MODE_APPEND = 'selection_append'; |
||
53 | |||
54 | /** |
||
55 | * Selection from entity browser will be prepended to existing list. |
||
56 | * |
||
57 | * When this selection mode is used, then entity browser will not be |
||
58 | * populated with existing selection. Preselected list will be empty. |
||
59 | * |
||
60 | * Note: This option is also used by "js/entity_browser.common.js". |
||
61 | */ |
||
62 | const SELECTION_MODE_PREPEND = 'selection_prepend'; |
||
63 | |||
64 | /** |
||
65 | * Selection from entity browser will replace existing. |
||
66 | * |
||
67 | * When this selection mode is used, then entity browser will be populated |
||
68 | * with existing selection and returned selected list will replace existing |
||
69 | * selection. This option requires entity browser selection display with |
||
70 | * preselection support. |
||
71 | * |
||
72 | * Note: This option is also used by "js/entity_browser.common.js". |
||
73 | */ |
||
74 | const SELECTION_MODE_EDIT = 'selection_edit'; |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function getInfo() { |
||
92 | |||
93 | /** |
||
94 | * Get selection mode options. |
||
95 | * |
||
96 | * @return array |
||
97 | * Selection mode options. |
||
98 | */ |
||
99 | public static function getSelectionModeOptions() { |
||
106 | |||
107 | /** |
||
108 | * Check whether entity browser should be available for selection of entities. |
||
109 | * |
||
110 | * @param string $selection_mode |
||
111 | * Used selection mode. |
||
112 | * @param int $cardinality |
||
113 | * Used cardinality. |
||
114 | * @param int $preselection_size |
||
115 | * Preseletion size, if it's available. |
||
116 | * |
||
117 | * @return bool |
||
118 | * Returns positive if entity browser can be used. |
||
119 | */ |
||
120 | public static function isEntityBrowserAvailable($selection_mode, $cardinality, $preselection_size) { |
||
131 | |||
132 | /** |
||
133 | * Render API callback: Processes the entity browser element. |
||
134 | */ |
||
135 | public static function processEntityBrowser(&$element, FormStateInterface $form_state, &$complete_form) { |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | public static function valueCallback(&$element, $input, FormStateInterface $form_state) { |
||
213 | |||
214 | /** |
||
215 | * Processes entity IDs and gets array of loaded entities. |
||
216 | * |
||
217 | * @param array|string $ids |
||
218 | * Processes entity IDs as they are returned from the entity browser. They |
||
219 | * are in [entity_type_id]:[entity_id] form. Array of IDs or a |
||
220 | * space-delimited string is supported. |
||
221 | * |
||
222 | * @return \Drupal\Core\Entity\EntityInterface[] |
||
223 | * Array of entity objects. |
||
224 | */ |
||
225 | public static function processEntityIds($ids) { |
||
238 | |||
239 | /** |
||
240 | * Processes entity IDs and gets array of loaded entities. |
||
241 | * |
||
242 | * @param string $id |
||
243 | * Processes entity ID as it is returned from the entity browser. ID should |
||
244 | * be in [entity_type_id]:[entity_id] form. |
||
245 | * |
||
246 | * @return \Drupal\Core\Entity\EntityInterface |
||
247 | * Entity object. |
||
248 | */ |
||
249 | public static function processEntityId($id) { |
||
253 | |||
254 | } |
||
255 |