X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FSelectionDisplayBase.php;fp=web%2Fmodules%2Fcontrib%2Fentity_browser%2Fsrc%2FSelectionDisplayBase.php;h=5df54d818e83788b1157367f7e81ba0f78a98e00;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entity_browser/src/SelectionDisplayBase.php b/web/modules/contrib/entity_browser/src/SelectionDisplayBase.php new file mode 100644 index 000000000..5df54d818 --- /dev/null +++ b/web/modules/contrib/entity_browser/src/SelectionDisplayBase.php @@ -0,0 +1,158 @@ +eventDispatcher = $event_dispatcher; + $this->entityTypeManager = $entity_type_manager; + $this->setConfiguration($configuration); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('event_dispatcher'), + $container->get('entity_type.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return []; + } + + /** + * {@inheritdoc} + */ + public function getConfiguration() { + return array_diff_key( + $this->configuration, + ['entity_browser_id' => 0] + ); + } + + /** + * {@inheritdoc} + */ + public function setConfiguration(array $configuration) { + $this->configuration = NestedArray::mergeDeep( + $this->defaultConfiguration(), + $configuration + ); + } + + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + return []; + } + + /** + * {@inheritdoc} + */ + public function label() { + $this->label; + } + + /** + * {@inheritdoc} + */ + public function validate(array &$form, FormStateInterface $form_state) {} + + /** + * {@inheritdoc} + */ + public function submit(array &$form, FormStateInterface $form_state) {} + + /** + * {@inheritdoc} + */ + public function checkPreselectionSupport() { + if (!$this->getPluginDefinition()['acceptPreselection']) { + throw new ConfigException('Used entity browser selection display does not support preselection.'); + } + } + + /** + * {@inheritdoc} + */ + public function supportsJsCommands() { + return $this->getPluginDefinition()['js_commands']; + } + + /** + * Marks selection as done - sets value in form state and dispatches event. + */ + protected function selectionDone(FormStateInterface $form_state) { + $form_state->set(['entity_browser', 'selection_completed'], TRUE); + $this->eventDispatcher->dispatch( + Events::DONE, + new SelectionDoneEvent( + $this->configuration['entity_browser_id'], + $form_state->get(['entity_browser', 'instance_uuid']) + )); + } + +}