1 | <?php |
||
36 | class EntityBrowserElement extends FormElement { |
||
37 | |||
38 | /** |
||
39 | * Indicating an entity browser can return an unlimited number of values. |
||
40 | * |
||
41 | * Note: When entity browser is used in Fields, cardinality is directly |
||
42 | * propagated from Field settings, that's why this constant should be equal to |
||
43 | * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED. |
||
44 | */ |
||
45 | const CARDINALITY_UNLIMITED = -1; |
||
46 | |||
47 | /** |
||
48 | * Selection from entity browser will be appended to existing list. |
||
49 | * |
||
50 | * When this selection mode is used, then entity browser will not be |
||
51 | * populated with existing selection. Preselected list will be empty. |
||
52 | * |
||
53 | * Note: This option is also used by "js/entity_browser.common.js". |
||
54 | */ |
||
55 | const SELECTION_MODE_APPEND = 'selection_append'; |
||
56 | |||
57 | /** |
||
58 | * Selection from entity browser will be prepended to existing list. |
||
59 | * |
||
60 | * When this selection mode is used, then entity browser will not be |
||
61 | * populated with existing selection. Preselected list will be empty. |
||
62 | * |
||
63 | * Note: This option is also used by "js/entity_browser.common.js". |
||
64 | */ |
||
65 | const SELECTION_MODE_PREPEND = 'selection_prepend'; |
||
66 | |||
67 | /** |
||
68 | * Selection from entity browser will replace existing. |
||
69 | * |
||
70 | * When this selection mode is used, then entity browser will be populated |
||
71 | * with existing selection and returned selected list will replace existing |
||
72 | * selection. This option requires entity browser selection display with |
||
73 | * preselection support. |
||
74 | * |
||
75 | * Note: This option is also used by "js/entity_browser.common.js". |
||
76 | */ |
||
77 | const SELECTION_MODE_EDIT = 'selection_edit'; |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function getInfo() { |
||
96 | |||
97 | /** |
||
98 | * Get selection mode options. |
||
99 | * |
||
100 | * @return array |
||
101 | * Selection mode options. |
||
102 | */ |
||
103 | public static function getSelectionModeOptions() { |
||
110 | |||
111 | /** |
||
112 | * Check whether entity browser should be available for selection of entities. |
||
113 | * |
||
114 | * @param string $selection_mode |
||
115 | * Used selection mode. |
||
116 | * @param int $cardinality |
||
117 | * Used cardinality. |
||
118 | * @param int $preselection_size |
||
119 | * Preseletion size, if it's available. |
||
120 | * |
||
121 | * @return bool |
||
122 | * Returns positive if entity browser can be used. |
||
123 | */ |
||
124 | public static function isEntityBrowserAvailable($selection_mode, $cardinality, $preselection_size) { |
||
135 | |||
136 | /** |
||
137 | * Render API callback: Processes the entity browser element. |
||
138 | */ |
||
139 | public static function processEntityBrowser(&$element, FormStateInterface $form_state, &$complete_form) { |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | public static function valueCallback(&$element, $input, FormStateInterface $form_state) { |
||
228 | |||
229 | /** |
||
230 | * Processes entity IDs and gets array of loaded entities. |
||
231 | * |
||
232 | * @param array|string $ids |
||
233 | * Processes entity IDs as they are returned from the entity browser. They |
||
234 | * are in [entity_type_id]:[entity_id] form. Array of IDs or a |
||
235 | * space-delimited string is supported. |
||
236 | * |
||
237 | * @return \Drupal\Core\Entity\EntityInterface[] |
||
238 | * Array of entity objects. |
||
239 | */ |
||
240 | public static function processEntityIds($ids) { |
||
253 | |||
254 | /** |
||
255 | * Processes entity IDs and gets array of loaded entities. |
||
256 | * |
||
257 | * @param string $id |
||
258 | * Processes entity ID as it is returned from the entity browser. ID should |
||
259 | * be in [entity_type_id]:[entity_id] form. |
||
260 | * |
||
261 | * @return \Drupal\Core\Entity\EntityInterface |
||
262 | * Entity object. |
||
263 | */ |
||
264 | public static function processEntityId($id) { |
||
268 | |||
269 | } |
||
270 |