From dd496a374ae898264a69ac22cca50a40125d19e8 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Thu, 3 Jul 2014 14:52:11 +0200 Subject: [PATCH 01/12] Issue #2291223 by slashrsm: Initial EntityBrowser entity. --- entity_browser.module | 19 ++++++++++ src/Entity/EntityBrowser.php | 66 ++++++++++++++++++++++++++++++++++ src/EntityBrowserInterface.php | 36 +++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 entity_browser.module create mode 100644 src/Entity/EntityBrowser.php create mode 100644 src/EntityBrowserInterface.php diff --git a/entity_browser.module b/entity_browser.module new file mode 100644 index 0000000..adeaf93 --- /dev/null +++ b/entity_browser.module @@ -0,0 +1,19 @@ + 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/src/Entity/EntityBrowser.php b/src/Entity/EntityBrowser.php new file mode 100644 index 0000000..49a6627 --- /dev/null +++ b/src/Entity/EntityBrowser.php @@ -0,0 +1,66 @@ +name; + } + + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name'); + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + +} diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php new file mode 100644 index 0000000..30cce3b --- /dev/null +++ b/src/EntityBrowserInterface.php @@ -0,0 +1,36 @@ + Date: Thu, 3 Jul 2014 15:23:27 +0200 Subject: [PATCH 02/12] Issue #2291223 by slashrsm: Add EntityBrowserDisplay plugin. --- entity_browser.api.php | 25 +++++++++++++ entity_browser.services.yml | 4 +++ src/Annotation/EntityBrowserDisplay.php | 48 +++++++++++++++++++++++++ src/EntityBrowserDisplayInterface.php | 25 +++++++++++++ src/EntityBrowserDisplayManager.php | 37 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 entity_browser.api.php create mode 100644 entity_browser.services.yml create mode 100644 src/Annotation/EntityBrowserDisplay.php create mode 100644 src/EntityBrowserDisplayInterface.php create mode 100644 src/EntityBrowserDisplayManager.php diff --git a/entity_browser.api.php b/entity_browser.api.php new file mode 100644 index 0000000..a24d77c --- /dev/null +++ b/entity_browser.api.php @@ -0,0 +1,25 @@ +alterInfo('entity_browser_display_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_display_plugins'); + } + +} From a78d4877693cd4d1c486ec7d6926f7bb03f9aaed Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Thu, 3 Jul 2014 16:01:23 +0200 Subject: [PATCH 03/12] Issue #2291223 by slashrsm: Add display to entity browser config entity. --- config/schema/entity_browser.schema.yml | 15 +++++++++++++++ src/Entity/EntityBrowser.php | 25 ++++++++++++++++++++++++- src/EntityBrowserInterface.php | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 config/schema/entity_browser.schema.yml diff --git a/config/schema/entity_browser.schema.yml b/config/schema/entity_browser.schema.yml new file mode 100644 index 0000000..5c0629d --- /dev/null +++ b/config/schema/entity_browser.schema.yml @@ -0,0 +1,15 @@ +# 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: string + label: 'Display' diff --git a/src/Entity/EntityBrowser.php b/src/Entity/EntityBrowser.php index 49a6627..f18ce55 100644 --- a/src/Entity/EntityBrowser.php +++ b/src/Entity/EntityBrowser.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityInterface; +use Drupal\entity_browser\EntityBrowserDisplayInterface; use Drupal\entity_browser\EntityBrowserInterface; /** @@ -18,7 +19,7 @@ * id = "entity_browser", * label = @Translation("Entity browser"), * admin_permission = "administer entity browsers", - * config_prefix = "entity_browser", + * config_prefix = "browser", * entity_keys = { * "id" = "name", * "label" = "label" @@ -41,6 +42,13 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, */ public $label; + /** + * The display plugin. + * + * @var \Drupal\entity_browser\EntityBrowserDisplayInterface + */ + public $display; + /** * {@inheritdoc} */ @@ -63,4 +71,19 @@ public function setName($name) { return $this; } + /** + * {@inheritdoc} + */ + public function getDisplay() { + return $this->get('display'); + } + + /** + * {@inheritdoc} + */ + public function setDisplay(EntityBrowserDisplayInterface $display) { + $this->set('display', $display); + return $this; + } + } diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php index 30cce3b..515081e 100644 --- a/src/EntityBrowserInterface.php +++ b/src/EntityBrowserInterface.php @@ -33,4 +33,23 @@ public function getName(); */ public function setName($name); + /** + * Returns the display. + * + * @return \Drupal\entity_browser\EntityBrowserDisplayInterface + * The display. + */ + public function getDisplay(); + + /** + * Sets the display. + * + * @param \Drupal\entity_browser\EntityBrowserDisplayInterface $display + * The display. + * + * @return \Drupal\entity_browser\EntityBrowserInterface + * The class instance this method is called on. + */ + public function setDisplay(EntityBrowserDisplayInterface $display); + } From c842923df6f9247b62ee94ea2ed921e7d2910f5d Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Thu, 3 Jul 2014 18:16:29 +0200 Subject: [PATCH 04/12] Issue #2291223 by slashrsm: Add EntityBrowserTab. --- entity_browser.api.php | 10 ++++ entity_browser.services.yml | 3 ++ src/Annotation/EntityBrowserDisplay.php | 2 +- src/Annotation/EntityBrowserTab.php | 56 ++++++++++++++++++++++ src/Entity/EntityBrowser.php | 63 ++++++++++++++++++++++++- src/EntityBrowserInterface.php | 40 ++++++++++++++++ src/EntityBrowserTabInterface.php | 33 +++++++++++++ src/EntityBrowserTabManager.php | 37 +++++++++++++++ 8 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 src/Annotation/EntityBrowserTab.php create mode 100644 src/EntityBrowserTabInterface.php create mode 100644 src/EntityBrowserTabManager.php diff --git a/entity_browser.api.php b/entity_browser.api.php index a24d77c..2296c1a 100644 --- a/entity_browser.api.php +++ b/entity_browser.api.php @@ -20,6 +20,16 @@ function hook_entity_browser_display_info_alter(&$displays) { $displays['modal_display']['label'] = t('Superb fancy stuff!'); } +/** + * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserTab. + * + * @param $tabs + * The array of tab plugins, keyed on the machine-readable name. + */ +function hook_entity_browser_tab_info_alter(&$displays) { + $displays['view_tab']['label'] = t('Views FTW!'); +} + /** * @} End of "addtogroup hooks". */ diff --git a/entity_browser.services.yml b/entity_browser.services.yml index bd25b3d..e2251c5 100644 --- a/entity_browser.services.yml +++ b/entity_browser.services.yml @@ -2,3 +2,6 @@ services: plugin.manager.entity_browser.display: class: Drupal\entity_browser\EntityBrowserDisplayManager parent: default_plugin_manager + plugin.manager.entity_browser.tab: + class: Drupal\entity_browser\EntityBrowserTabManager + parent: default_plugin_manager diff --git a/src/Annotation/EntityBrowserDisplay.php b/src/Annotation/EntityBrowserDisplay.php index 98db126..9017be6 100644 --- a/src/Annotation/EntityBrowserDisplay.php +++ b/src/Annotation/EntityBrowserDisplay.php @@ -10,7 +10,7 @@ use Drupal\Component\Annotation\Plugin; /** - * Defines an image effect annotation object. + * Defines an entity browser display annotation object. * * @see hook_entity_browser_display_info_alter() * diff --git a/src/Annotation/EntityBrowserTab.php b/src/Annotation/EntityBrowserTab.php new file mode 100644 index 0000000..88d9f4c --- /dev/null +++ b/src/Annotation/EntityBrowserTab.php @@ -0,0 +1,56 @@ + $this->getTabs()); + } + + /** + * {@inheritdoc} + */ + public function getTab($tab) { + return $this->getTabs()->get($tab); + } + + /** + * {@inheritdoc} + */ + public function getTabs() { + if (!$this->tabsBag) { + $this->tabsBag = new DefaultPluginBag(\Drupal::service('plugin.manager.entity_browser.tab'), $this->tabs); + $this->tabsBag->sort(); + } + return $this->tabsBag; + } + + /** + * {@inheritdoc} + */ + public function addTab(array $configuration) { + $configuration['uuid'] = $this->uuidGenerator()->generate(); + $this->getTabs()->addInstanceId($configuration['uuid'], $configuration); + return $configuration['uuid']; + } + + /** + * {@inheritdoc} + */ + public function deleteTab(EntityBrowserTabInterface $tab) { + $this->getTabs()->removeInstanceId($tab->getUuid()); + $this->save(); + return $this; + } + } diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php index 515081e..1a823b8 100644 --- a/src/EntityBrowserInterface.php +++ b/src/EntityBrowserInterface.php @@ -52,4 +52,44 @@ public function getDisplay(); */ public function setDisplay(EntityBrowserDisplayInterface $display); + /** + * Returns a specific tab. + * + * @param string $tab + * The tab ID. + * + * @return \Drupal\entity_browser\EntityBrowserTabInterface + * The tab object. + */ + public function getTab($tab); + + /** + * Returns the tabs for this entity browser. + * + * @return \Drupal\Core\Plugin\DefaultPluginBag + * The tag plugin bag. + */ + public function getTabs(); + + /** + * Saves a tab for this entity browser. + * + * @param array $configuration + * An array of tab configuration. + * + * @return string + * The tab ID. + */ + public function addTab(array $configuration); + + /** + * Deletes a tab from this entity browser. + * + * @param \Drupal\entity_browser\EntityBrowserTabInterface $tab + * The tab object. + * + * @return $this + */ + public function deleteTab(EntityBrowserTabInterface $tab); + } diff --git a/src/EntityBrowserTabInterface.php b/src/EntityBrowserTabInterface.php new file mode 100644 index 0000000..91fecb3 --- /dev/null +++ b/src/EntityBrowserTabInterface.php @@ -0,0 +1,33 @@ +alterInfo('entity_browser_tab_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_tab_plugins'); + } + +} From 2be3a2cf3b8de0d152ba75c2667a0c9de4d89574 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Thu, 3 Jul 2014 19:34:36 +0200 Subject: [PATCH 05/12] Issue #2291223 by slashrsm: Fix typo. --- src/Annotation/EntityBrowserTab.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Annotation/EntityBrowserTab.php b/src/Annotation/EntityBrowserTab.php index 88d9f4c..989f471 100644 --- a/src/Annotation/EntityBrowserTab.php +++ b/src/Annotation/EntityBrowserTab.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity_browser\Annotation\EntityBrowserDisplay. + * Contains \Drupal\entity_browser\Annotation\EntityBrowserTab. */ namespace Drupal\entity_browser\Annotation; From f0972fabb186a9722b2f7ad209c5f0c9699d28ef Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Mon, 21 Jul 2014 15:46:23 +0200 Subject: [PATCH 06/12] Issue #2291223 by slashrsm: Rename tabs to widgets. --- entity_browser.api.php | 10 ++-- entity_browser.services.yml | 4 +- src/Annotation/EntityBrowserTab.php | 56 ------------------- src/Annotation/EntityBrowserWidget.php | 48 ++++++++++++++++ src/Entity/EntityBrowser.php | 34 +++++------ src/EntityBrowserInterface.php | 32 +++++------ src/EntityBrowserTabInterface.php | 33 ----------- src/EntityBrowserWidgetInterface.php | 33 +++++++++++ ...ger.php => EntityBrowserWidgetManager.php} | 14 ++--- 9 files changed, 128 insertions(+), 136 deletions(-) delete mode 100644 src/Annotation/EntityBrowserTab.php create mode 100644 src/Annotation/EntityBrowserWidget.php delete mode 100644 src/EntityBrowserTabInterface.php create mode 100644 src/EntityBrowserWidgetInterface.php rename src/{EntityBrowserTabManager.php => EntityBrowserWidgetManager.php} (61%) diff --git a/entity_browser.api.php b/entity_browser.api.php index 2296c1a..0742008 100644 --- a/entity_browser.api.php +++ b/entity_browser.api.php @@ -21,13 +21,13 @@ function hook_entity_browser_display_info_alter(&$displays) { } /** - * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserTab. + * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserWidget. * - * @param $tabs - * The array of tab plugins, keyed on the machine-readable name. + * @param $widgets + * The array of widget plugins, keyed on the machine-readable name. */ -function hook_entity_browser_tab_info_alter(&$displays) { - $displays['view_tab']['label'] = t('Views FTW!'); +function hook_entity_browser_widget_info_alter(&$widgets) { + $widgets['view_widget']['label'] = t('Views FTW!'); } /** diff --git a/entity_browser.services.yml b/entity_browser.services.yml index e2251c5..187faa3 100644 --- a/entity_browser.services.yml +++ b/entity_browser.services.yml @@ -2,6 +2,6 @@ services: plugin.manager.entity_browser.display: class: Drupal\entity_browser\EntityBrowserDisplayManager parent: default_plugin_manager - plugin.manager.entity_browser.tab: - class: Drupal\entity_browser\EntityBrowserTabManager + plugin.manager.entity_browser.widget: + class: Drupal\entity_browser\EntityBrowserWidgetManager parent: default_plugin_manager diff --git a/src/Annotation/EntityBrowserTab.php b/src/Annotation/EntityBrowserTab.php deleted file mode 100644 index 989f471..0000000 --- a/src/Annotation/EntityBrowserTab.php +++ /dev/null @@ -1,56 +0,0 @@ - $this->getTabs()); + return array('widgets' => $this->getWidgets()); } /** * {@inheritdoc} */ - public function getTab($tab) { - return $this->getTabs()->get($tab); + public function getWidget($widget) { + return $this->getWidgets()->get($widget); } /** * {@inheritdoc} */ - public function getTabs() { - if (!$this->tabsBag) { - $this->tabsBag = new DefaultPluginBag(\Drupal::service('plugin.manager.entity_browser.tab'), $this->tabs); - $this->tabsBag->sort(); + public function getWidgets() { + if (!$this->widgetsBag) { + $this->widgetsBag = new DefaultPluginBag(\Drupal::service('plugin.manager.entity_browser.widget'), $this->widgets); + $this->widgetsBag->sort(); } - return $this->tabsBag; + return $this->widgetsBag; } /** * {@inheritdoc} */ - public function addTab(array $configuration) { + public function addWidget(array $configuration) { $configuration['uuid'] = $this->uuidGenerator()->generate(); - $this->getTabs()->addInstanceId($configuration['uuid'], $configuration); + $this->getWidgets()->addInstanceId($configuration['uuid'], $configuration); return $configuration['uuid']; } /** * {@inheritdoc} */ - public function deleteTab(EntityBrowserTabInterface $tab) { - $this->getTabs()->removeInstanceId($tab->getUuid()); + public function deleteWidget(EntityBrowserWidgetInterface $widget) { + $this->getWidgets()->removeInstanceId($widget->getUuid()); $this->save(); return $this; } diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php index 1a823b8..718769e 100644 --- a/src/EntityBrowserInterface.php +++ b/src/EntityBrowserInterface.php @@ -53,43 +53,43 @@ public function getDisplay(); public function setDisplay(EntityBrowserDisplayInterface $display); /** - * Returns a specific tab. + * Returns a specific widget. * - * @param string $tab - * The tab ID. + * @param string $widget + * The widget ID. * - * @return \Drupal\entity_browser\EntityBrowserTabInterface - * The tab object. + * @return \Drupal\entity_browser\EntityBrowserWidgetInterface + * The widget object. */ - public function getTab($tab); + public function getWidget($widget); /** - * Returns the tabs for this entity browser. + * Returns the widgets for this entity browser. * * @return \Drupal\Core\Plugin\DefaultPluginBag * The tag plugin bag. */ - public function getTabs(); + public function getWidgets(); /** - * Saves a tab for this entity browser. + * Saves a widget for this entity browser. * * @param array $configuration - * An array of tab configuration. + * An array of widget configuration. * * @return string - * The tab ID. + * The widget ID. */ - public function addTab(array $configuration); + public function addWidget(array $configuration); /** - * Deletes a tab from this entity browser. + * Deletes a widget from this entity browser. * - * @param \Drupal\entity_browser\EntityBrowserTabInterface $tab - * The tab object. + * @param \Drupal\entity_browser\EntityBrowserWidgetInterface $widget + * The widget object. * * @return $this */ - public function deleteTab(EntityBrowserTabInterface $tab); + public function deleteWidget(EntityBrowserWidgetInterface $widget); } diff --git a/src/EntityBrowserTabInterface.php b/src/EntityBrowserTabInterface.php deleted file mode 100644 index 91fecb3..0000000 --- a/src/EntityBrowserTabInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -alterInfo('entity_browser_tab_info'); - $this->setCacheBackend($cache_backend, 'entity_browser_tab_plugins'); + $this->alterInfo('entity_browser_widget_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_widget_plugins'); } } From 3346b1baec767080c8ae787ec58a7eb84f2d7766 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Mon, 21 Jul 2014 16:00:26 +0200 Subject: [PATCH 07/12] Issue #2291223 by slashrsm: Add selection display plugin manager, interface and annotation object. --- entity_browser.api.php | 11 +++++ .../EntityBrowserSelectionDisplay.php | 48 +++++++++++++++++++ ...EntityBrowserSelectionDisplayInterface.php | 25 ++++++++++ src/EntityBrowserSelectionDisplayManager.php | 37 ++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 src/Annotation/EntityBrowserSelectionDisplay.php create mode 100644 src/EntityBrowserSelectionDisplayInterface.php create mode 100644 src/EntityBrowserSelectionDisplayManager.php diff --git a/entity_browser.api.php b/entity_browser.api.php index 0742008..14f5359 100644 --- a/entity_browser.api.php +++ b/entity_browser.api.php @@ -30,6 +30,17 @@ function hook_entity_browser_widget_info_alter(&$widgets) { $widgets['view_widget']['label'] = t('Views FTW!'); } +/** + * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserSelectionDisplay. + * + * @param $widgets + * The array of selection display plugins, keyed on the machine-readable name. + */ +function hook_entity_browser_selection_display_info_alter(&$selection_displays) { + $selection_displays['no_selection']['label'] = t('Nothing!'); +} + + /** * @} End of "addtogroup hooks". */ diff --git a/src/Annotation/EntityBrowserSelectionDisplay.php b/src/Annotation/EntityBrowserSelectionDisplay.php new file mode 100644 index 0000000..b5d224b --- /dev/null +++ b/src/Annotation/EntityBrowserSelectionDisplay.php @@ -0,0 +1,48 @@ +alterInfo('entity_browser_selection_display_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_selection_display_plugins'); + } + +} From 9a45cf610f9c6fa6ff67e37c1652f9adbc3f3e6c Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Mon, 21 Jul 2014 16:27:36 +0200 Subject: [PATCH 08/12] Issue #2291223 by slashrsm: Add widget selector plugin. --- entity_browser.api.php | 11 +++++ entity_browser.services.yml | 6 +++ .../EntityBrowserWidgetSelector.php | 48 +++++++++++++++++++ src/EntityBrowserWidgetSelectorInterface.php | 33 +++++++++++++ src/EntityBrowserWidgetSelectorManager.php | 37 ++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 src/Annotation/EntityBrowserWidgetSelector.php create mode 100644 src/EntityBrowserWidgetSelectorInterface.php create mode 100644 src/EntityBrowserWidgetSelectorManager.php diff --git a/entity_browser.api.php b/entity_browser.api.php index 14f5359..d9023b2 100644 --- a/entity_browser.api.php +++ b/entity_browser.api.php @@ -40,6 +40,17 @@ function hook_entity_browser_selection_display_info_alter(&$selection_displays) $selection_displays['no_selection']['label'] = t('Nothing!'); } +/** + * Alter the information provided in \Drupal\entity_browser\Annotation\EntityBrowserWidgetSelector. + * + * @param $widget_selectors + * The array of widget selector plugins, keyed on the machine-readable name. + */ +function hook_entity_browser_widget_selector_info_alter(&$widgets) { + $widgets['tab_selector']['label'] = t('Tabs are for winners'); +} + + /** * @} End of "addtogroup hooks". diff --git a/entity_browser.services.yml b/entity_browser.services.yml index 187faa3..03b6f87 100644 --- a/entity_browser.services.yml +++ b/entity_browser.services.yml @@ -2,6 +2,12 @@ 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/EntityBrowserWidgetSelector.php b/src/Annotation/EntityBrowserWidgetSelector.php new file mode 100644 index 0000000..6fc95ac --- /dev/null +++ b/src/Annotation/EntityBrowserWidgetSelector.php @@ -0,0 +1,48 @@ +alterInfo('entity_browser_widget_selector_info'); + $this->setCacheBackend($cache_backend, 'entity_browser_widget_selector_plugins'); + } + +} From c6dc01660d7b146f304f415875629fbedc2ab743 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Tue, 22 Jul 2014 11:35:47 +0200 Subject: [PATCH 09/12] Issue #2291223 by slashrsm: Add configuration schema and bags for all plugins. --- config/schema/entity_browser.schema.yml | 49 +++++++- src/Entity/EntityBrowser.php | 113 +++++++++++++++++- src/EntityBrowserInterface.php | 45 ++++++- ...EntityBrowserSelectionDisplayInterface.php | 2 +- src/EntityBrowserWidgetInterface.php | 8 ++ 5 files changed, 209 insertions(+), 8 deletions(-) diff --git a/config/schema/entity_browser.schema.yml b/config/schema/entity_browser.schema.yml index 5c0629d..4270a50 100644 --- a/config/schema/entity_browser.schema.yml +++ b/config/schema/entity_browser.schema.yml @@ -11,5 +11,52 @@ entity_browser.browser.*: type: label label: 'Label' display: - type: string + 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/src/Entity/EntityBrowser.php b/src/Entity/EntityBrowser.php index 5e322dd..3ff9320 100644 --- a/src/Entity/EntityBrowser.php +++ b/src/Entity/EntityBrowser.php @@ -10,9 +10,12 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityWithPluginBagsInterface; use Drupal\Core\Plugin\DefaultPluginBag; +use Drupal\Core\Plugin\DefaultSinglePluginBag; use Drupal\entity_browser\EntityBrowserDisplayInterface; use Drupal\entity_browser\EntityBrowserInterface; +use Drupal\entity_browser\EntityBrowserSelectionDisplayInterface; use Drupal\entity_browser\EntityBrowserWidgetInterface; +use Drupal\entity_browser\EntityBrowserWidgetSelectorInterface; /** * Defines an entity browser configuration entity. @@ -45,12 +48,19 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, public $label; /** - * The display plugin. + * The display plugin configuration. * - * @var \Drupal\entity_browser\EntityBrowserDisplayInterface + * @var array */ public $display; + /** + * Display plugin bag. + * + * @var \Drupal\Core\Plugin\DefaultSinglePluginBag + */ + protected $displayBag; + /** * The array of widgets for this entity browser. * @@ -65,6 +75,34 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, */ protected $widgetsBag; + /** + * The selection display plugin configuration. + * + * @var array + */ + public $selectionDisplay; + + /** + * Selection display plugin bag. + * + * @var \Drupal\Core\Plugin\DefaultSinglePluginBag + */ + protected $selectionDisplayBag; + + /** + * The widget selector plugin configuration. + * + * @var array + */ + public $widgetSelector; + + /** + * Widget selector plugin bag. + * + * @var \Drupal\Core\Plugin\DefaultSinglePluginBag + */ + protected $widgetSelectorBag; + /** * {@inheritdoc} */ @@ -94,10 +132,23 @@ 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(EntityBrowserDisplayInterface $display) { + public function setDisplay(array $display) { $this->set('display', $display); return $this; } @@ -145,4 +196,60 @@ public function deleteWidget(EntityBrowserWidgetInterface $widget) { 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->selectionDisplay['id'], $this->selectionDisplay); + } + return $this->selectionDisplayBag; + } + + /** + * {@inheritdoc} + */ + public function getSelectionDisplay() { + $this->selectionDisplayPluginBag()->get($this->selectionDisplay['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->widgetSelector['id'], $this->widgetSelector); + } + return $this->widgetSelectorBag; + } + + /** + * {@inheritdoc} + */ + public function getWidgetSelector() { + $this->widgetSelectorPluginBag()->get($this->widgetSelector['id']); + } + + /** + * {@inheritdoc} + */ + public function setWidgetSelector(array $widget_selector) { + $this->set('widgetSelector', $widget_selector); + return $this; + } + } diff --git a/src/EntityBrowserInterface.php b/src/EntityBrowserInterface.php index 718769e..d54adad 100644 --- a/src/EntityBrowserInterface.php +++ b/src/EntityBrowserInterface.php @@ -44,13 +44,13 @@ public function getDisplay(); /** * Sets the display. * - * @param \Drupal\entity_browser\EntityBrowserDisplayInterface $display - * The display. + * @param array $display + * The display configuration. * * @return \Drupal\entity_browser\EntityBrowserInterface * The class instance this method is called on. */ - public function setDisplay(EntityBrowserDisplayInterface $display); + public function setDisplay(array $display); /** * Returns a specific widget. @@ -92,4 +92,43 @@ public function addWidget(array $configuration); */ public function deleteWidget(EntityBrowserWidgetInterface $widget); + /** + * Returns the selection display. + * + * @return \Drupal\entity_browser\EntityBrowserSelectionDisplayInterface + * The display. + */ + public function getSelectionDisplay(); + + /** + * Sets the selection display. + * + * @param array $selection_display + * The selection display configuration. + * + * @return \Drupal\entity_browser\EntityBrowserInterface + * The class instance this method is called on. + */ + public function setSelectionDisplay(array $selection_display); + + + /** + * Returns the widget selector. + * + * @return \Drupal\entity_browser\EntityBrowserWidgetSelectorInterface + * The widget selector. + */ + public function getWidgetSelector(); + + /** + * Sets the widget selector. + * + * @param array $widget_selector + * The widget selector configuration. + * + * @return \Drupal\entity_browser\EntityBrowserInterface + * The class instance this method is called on. + */ + public function setWidgetSelector(array $widget_selector); + } diff --git a/src/EntityBrowserSelectionDisplayInterface.php b/src/EntityBrowserSelectionDisplayInterface.php index 015a0ae..53c05b6 100644 --- a/src/EntityBrowserSelectionDisplayInterface.php +++ b/src/EntityBrowserSelectionDisplayInterface.php @@ -12,7 +12,7 @@ /** * Defines the interface for entity browser selection displays. */ -interface EntityBrowserDisplayInterface extends PluginInspectionInterface { +interface EntityBrowserSelectionDisplayInterface extends PluginInspectionInterface { /** * Returns the selection display label. diff --git a/src/EntityBrowserWidgetInterface.php b/src/EntityBrowserWidgetInterface.php index 97dee56..a6cf350 100644 --- a/src/EntityBrowserWidgetInterface.php +++ b/src/EntityBrowserWidgetInterface.php @@ -30,4 +30,12 @@ public function label(); */ public function getUuid(); + /** + * Returns the widget's weight. + * + * @return int + * Widget's weight. + */ + public function getWeight(); + } From 5fbfa75e107b70c3bf2196cdc178a0691352a9ed Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Wed, 23 Jul 2014 12:00:18 +0200 Subject: [PATCH 10/12] Issue #2291223 by slashrsm: Match class member names with config schema. --- src/Entity/EntityBrowser.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Entity/EntityBrowser.php b/src/Entity/EntityBrowser.php index 3ff9320..c9b7156 100644 --- a/src/Entity/EntityBrowser.php +++ b/src/Entity/EntityBrowser.php @@ -66,7 +66,7 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, * * @var array */ - protected $widgets = array(); + protected $widgets; /** * Holds the collection of widgetss that are used by this entity browser. @@ -80,7 +80,7 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, * * @var array */ - public $selectionDisplay; + public $selection_display; /** * Selection display plugin bag. @@ -94,7 +94,7 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface, * * @var array */ - public $widgetSelector; + public $widget_selector; /** * Widget selector plugin bag. @@ -204,7 +204,7 @@ public function deleteWidget(EntityBrowserWidgetInterface $widget) { */ protected function selectionDisplayPluginBag() { if (!$this->selectionDisplayBag) { - $this->selectionDisplayBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.selection_display'), $this->selectionDisplay['id'], $this->selectionDisplay); + $this->selectionDisplayBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.selection_display'), $this->selection_display['id'], $this->selection_display); } return $this->selectionDisplayBag; } @@ -213,7 +213,7 @@ protected function selectionDisplayPluginBag() { * {@inheritdoc} */ public function getSelectionDisplay() { - $this->selectionDisplayPluginBag()->get($this->selectionDisplay['id']); + $this->selectionDisplayPluginBag()->get($this->selection_display['id']); } /** @@ -232,7 +232,7 @@ public function setSelectionDisplay(array $selection_display) { */ protected function widgetSelectorPluginBag() { if (!$this->widgetSelectorBag) { - $this->widgetSelectorBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.widget_selector'), $this->widgetSelector['id'], $this->widgetSelector); + $this->widgetSelectorBag = new DefaultSinglePluginBag(\Drupal::service('plugin.manager.entity_browser.widget_selector'), $this->widget_selector['id'], $this->widget_selector); } return $this->widgetSelectorBag; } @@ -241,7 +241,7 @@ protected function widgetSelectorPluginBag() { * {@inheritdoc} */ public function getWidgetSelector() { - $this->widgetSelectorPluginBag()->get($this->widgetSelector['id']); + $this->widgetSelectorPluginBag()->get($this->widget_selector['id']); } /** From 27c6aed4d6bbcff4e2a3fa2cc62293801f927211 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Wed, 23 Jul 2014 12:05:44 +0200 Subject: [PATCH 11/12] Issue #2291223 by slashrsm: Add another directory level for all entity browser plugin types. --- src/EntityBrowserDisplayManager.php | 2 +- src/EntityBrowserSelectionDisplayManager.php | 2 +- src/EntityBrowserWidgetManager.php | 2 +- src/EntityBrowserWidgetSelectorManager.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EntityBrowserDisplayManager.php b/src/EntityBrowserDisplayManager.php index 86e42ca..8c957ea 100644 --- a/src/EntityBrowserDisplayManager.php +++ b/src/EntityBrowserDisplayManager.php @@ -28,7 +28,7 @@ class EntityBrowserDisplayManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/EntityBrowserDisplay', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserDisplay'); + parent::__construct('Plugin/EntityBrowser/Display', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserDisplay'); $this->alterInfo('entity_browser_display_info'); $this->setCacheBackend($cache_backend, 'entity_browser_display_plugins'); diff --git a/src/EntityBrowserSelectionDisplayManager.php b/src/EntityBrowserSelectionDisplayManager.php index a77d8e8..d0937dc 100644 --- a/src/EntityBrowserSelectionDisplayManager.php +++ b/src/EntityBrowserSelectionDisplayManager.php @@ -28,7 +28,7 @@ class EntityBrowserSelectionDisplayManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/EntityBrowserSelectionDisplay', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserSelectionDisplay'); + parent::__construct('Plugin/EntityBrowser/SelectionDisplay', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserSelectionDisplay'); $this->alterInfo('entity_browser_selection_display_info'); $this->setCacheBackend($cache_backend, 'entity_browser_selection_display_plugins'); diff --git a/src/EntityBrowserWidgetManager.php b/src/EntityBrowserWidgetManager.php index 073d43c..b8bc723 100644 --- a/src/EntityBrowserWidgetManager.php +++ b/src/EntityBrowserWidgetManager.php @@ -28,7 +28,7 @@ class EntityBrowserWidgetManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/EntityBrowserWidget', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserWidget'); + parent::__construct('Plugin/EntityBrowser/Widget', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserWidget'); $this->alterInfo('entity_browser_widget_info'); $this->setCacheBackend($cache_backend, 'entity_browser_widget_plugins'); diff --git a/src/EntityBrowserWidgetSelectorManager.php b/src/EntityBrowserWidgetSelectorManager.php index 7b024d0..b7c09e3 100644 --- a/src/EntityBrowserWidgetSelectorManager.php +++ b/src/EntityBrowserWidgetSelectorManager.php @@ -28,7 +28,7 @@ class EntityBrowserWidgetSelectorManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/EntityBrowserWidgetSelector', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserWidgetSelector'); + parent::__construct('Plugin/EntityBrowser/WidgetSelector', $namespaces, $module_handler, 'Drupal\entity_browser\Annotation\EntityBrowserWidgetSelector'); $this->alterInfo('entity_browser_widget_selector_info'); $this->setCacheBackend($cache_backend, 'entity_browser_widget_selector_plugins'); From a634d6dafc0e0d6732203aedb59eab06a5c8f350 Mon Sep 17 00:00:00 2001 From: Janez Urevc Date: Wed, 23 Jul 2014 12:23:45 +0200 Subject: [PATCH 12/12] Issue #2291253 by slashrsm: Create very basic implementation of first selection display plugin. --- .../SelectionDisplay/NoDisplay.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Plugin/EntityBrowser/SelectionDisplay/NoDisplay.php 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; + } + +}