diff --git a/config/schema/entity_browser.schema.yml b/config/schema/entity_browser.schema.yml new file mode 100644 index 0000000..4270a50 --- /dev/null +++ b/config/schema/entity_browser.schema.yml @@ -0,0 +1,62 @@ +# Schema for configuration files of the Entity browser module. + +entity_browser.browser.*: + type: config_entity + label: 'Entity browser' + mapping: + name: + type: string + label: 'Machine name' + label: + type: label + label: 'Label' + display: + type: 'mapping' + label: 'Display' + mapping: + id: + type: string + uuid: + type: string + label: + type: string + settings: + type: entity_browser.browser.display.[%parent.id] + widgets: + type: sequence + label: 'Widgets' + sequence: + - type: mapping + mapping: + id: + type: string + uuid: + type: string + label: + type: string + weight: + type: integer + settings: + type: entity_browser.browser.widget.[%parent.id] + widget_selector: + type: mapping + mapping: + id: + type: string + uuid: + type: string + label: + type: string + settings: + type: entity_browser.browser.widget_selector.[%parent.id] + selection_display: + type: mapping + mapping: + id: + type: string + uuid: + type: string + label: + type: string + settings: + type: entity_browser.browser.selection_display.[%parent.id] diff --git a/entity_browser.api.php b/entity_browser.api.php new file mode 100644 index 0000000..d9023b2 --- /dev/null +++ b/entity_browser.api.php @@ -0,0 +1,57 @@ + array( + 'title' => t('Administer entity browsers'), + 'description' => t('Create and modify entity browsers for generating browsing, creating and selecting entities.'), + 'restrict access' => TRUE, + ), + ); +} diff --git a/entity_browser.services.yml b/entity_browser.services.yml new file mode 100644 index 0000000..03b6f87 --- /dev/null +++ b/entity_browser.services.yml @@ -0,0 +1,13 @@ +services: + plugin.manager.entity_browser.display: + class: Drupal\entity_browser\EntityBrowserDisplayManager + parent: default_plugin_manager + plugin.manager.entity_browser.selection_display: + class: Drupal\entity_browser\EntityBrowserSelectionDisplayManager + parent: default_plugin_manager + plugin.manager.entity_browser.widget: + class: Drupal\entity_browser\EntityBrowserWidgetManager + parent: default_plugin_manager + plugin.manager.entity_browser.widget_selector: + class: Drupal\entity_browser\EntityBrowserWidgetSelectorManager + parent: default_plugin_manager diff --git a/src/Annotation/EntityBrowserDisplay.php b/src/Annotation/EntityBrowserDisplay.php new file mode 100644 index 0000000..9017be6 --- /dev/null +++ b/src/Annotation/EntityBrowserDisplay.php @@ -0,0 +1,48 @@ +name; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name'); + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getDisplay() { + return $this->get('display'); + } + + /** + * Returns display plugin bag. + * + * @return \Drupal\Core\Plugin\DefaultSinglePluginBag + * The tag plugin bag. + */ + protected function displayPluginBag() { + if (!$this->displayBag) { + $this->displayBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.display'), $this->display['id'], $this->display); + } + return $this->displayBag; + } + + /** + * {@inheritdoc} + */ + public function setDisplay(array $display) { + $this->set('display', $display); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getPluginBags() { + return array('widgets' => $this->getWidgets()); + } + + /** + * {@inheritdoc} + */ + public function getWidget($widget) { + return $this->getWidgets()->get($widget); + } + + /** + * {@inheritdoc} + */ + public function getWidgets() { + if (!$this->widgetsBag) { + $this->widgetsBag = new DefaultPluginBag(\Drupal::service('plugin.manager.entity_browser.widget'), $this->widgets); + $this->widgetsBag->sort(); + } + return $this->widgetsBag; + } + + /** + * {@inheritdoc} + */ + public function addWidget(array $configuration) { + $configuration['uuid'] = $this->uuidGenerator()->generate(); + $this->getWidgets()->addInstanceId($configuration['uuid'], $configuration); + return $configuration['uuid']; + } + + /** + * {@inheritdoc} + */ + public function deleteWidget(EntityBrowserWidgetInterface $widget) { + $this->getWidgets()->removeInstanceId($widget->getUuid()); + $this->save(); + return $this; + } + + /** + * Returns selection display plugin bag. + * + * @return \Drupal\Core\Plugin\DefaultSinglePluginBag + * The tag plugin bag. + */ + protected function selectionDisplayPluginBag() { + if (!$this->selectionDisplayBag) { + $this->selectionDisplayBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.selection_display'), $this->selection_display['id'], $this->selection_display); + } + return $this->selectionDisplayBag; + } + + /** + * {@inheritdoc} + */ + public function getSelectionDisplay() { + $this->selectionDisplayPluginBag()->get($this->selection_display['id']); + } + + /** + * {@inheritdoc} + */ + public function setSelectionDisplay(array $selection_display) { + $this->set('selectionDisplay', $selection_display); + return $this; + } + + /** + * Returns widget selector plugin bag. + * + * @return \Drupal\Core\Plugin\DefaultSinglePluginBag + * The tag plugin bag. + */ + protected function widgetSelectorPluginBag() { + if (!$this->widgetSelectorBag) { + $this->widgetSelectorBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.widget_selector'), $this->widget_selector['id'], $this->widget_selector); + } + return $this->widgetSelectorBag; + } + + /** + * {@inheritdoc} + */ + public function getWidgetSelector() { + $this->widgetSelectorPluginBag()->get($this->widget_selector['id']); + } + + /** + * {@inheritdoc} + */ + public function setWidgetSelector(array $widget_selector) { + $this->set('widgetSelector', $widget_selector); + return $this; + } + +} diff --git a/src/EntityBrowserDisplayInterface.php b/src/EntityBrowserDisplayInterface.php new file mode 100644 index 0000000..2cbc022 --- /dev/null +++ b/src/EntityBrowserDisplayInterface.php @@ -0,0 +1,25 @@ +alterInfo('entity_browser_display_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_display_plugins'); + } + +} diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php new file mode 100644 index 0000000..d54adad --- /dev/null +++ b/src/EntityBrowserInterface.php @@ -0,0 +1,134 @@ +alterInfo('entity_browser_selection_display_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_selection_display_plugins'); + } + +} diff --git a/src/EntityBrowserWidgetInterface.php b/src/EntityBrowserWidgetInterface.php new file mode 100644 index 0000000..a6cf350 --- /dev/null +++ b/src/EntityBrowserWidgetInterface.php @@ -0,0 +1,41 @@ +alterInfo('entity_browser_widget_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_widget_plugins'); + } + +} diff --git a/src/EntityBrowserWidgetSelectorInterface.php b/src/EntityBrowserWidgetSelectorInterface.php new file mode 100644 index 0000000..e4bcdf6 --- /dev/null +++ b/src/EntityBrowserWidgetSelectorInterface.php @@ -0,0 +1,33 @@ +alterInfo('entity_browser_widget_selector_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_widget_selector_plugins'); + } + +} diff --git a/src/Plugin/EntityBrowser/SelectionDisplay/NoDisplay.php b/src/Plugin/EntityBrowser/SelectionDisplay/NoDisplay.php new file mode 100644 index 0000000..246898d --- /dev/null +++ b/src/Plugin/EntityBrowser/SelectionDisplay/NoDisplay.php @@ -0,0 +1,37 @@ +label; + } + +}