Skip to content

Commit

Permalink
Issue #2512702 by slashrsm, Lukas von Blarer, CTaPByK, EclipseGc: Imp…
Browse files Browse the repository at this point in the history
…lement configuration UI
  • Loading branch information
slashrsm committed Feb 19, 2016
1 parent 48b2710 commit fbaab63
Show file tree
Hide file tree
Showing 35 changed files with 1,348 additions and 28 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ Provides standardized interface to list, create and select entities.
## Requirements

* Latest dev release of Drupal 8.x.
* [Chaos tool set](https://drupal.org/project/ctools) (soft dependency for configuration UI)

## Configuration

There is no UI to configure entity browsers ATM. In order to test this module
you need to import yml files using drush or configuration management admin pages
(admin/config/development/configuration/single/import).
Module ships with a simple configuration UI which allows you to create, edit
and delete entity browsers. It depends on
[Chaos tool set](https://drupal.org/project/ctools). Enable it and navigate to
/admin/config/content/entity_browser.

We also provided a module that will create:
- content type with two entity reference fields
- two entity browsers (listing files and nodes)
- a view that is used on nodes entity browser
- form display configuration for entity reference fields to use entity browsers

In order to use this configuration for testing or to help you contribute just
enable "Entity Browser example" module (entity_browser_example).

Expand Down
3 changes: 3 additions & 0 deletions config/schema/entity_browser.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ entity_browser.browser.display.iframe:
link_text:
type: string
label: 'Link text'
auto_open:
type: boolean
label: 'Auto open'

entity_browser.browser.display.modal:
type: mapping
Expand Down
2 changes: 1 addition & 1 deletion entity_browser.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ type: module
package: Media
core: 8.x
test_dependencies:
- ctools
- ctools
12 changes: 12 additions & 0 deletions entity_browser.links.action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
media.bundle_add:
route_name: media.bundle_add
title: 'Add media bundle'
appears_on:
- entity.media_bundle.collection

entity_browser.add:
route_name: entity.entity_browser.add_form
title: 'Add Entity browser'
weight: 0
appears_on:
- entity.entity_browser.collection
5 changes: 5 additions & 0 deletions entity_browser.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entity.entity_browser.collection:
title: 'Entity browsers'
parent: system.admin_config_content
description: 'Manage entity browsers.'
route_name: entity.entity_browser.collection
34 changes: 34 additions & 0 deletions entity_browser.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,37 @@ entity_browser.edit_form:
parameters:
entity:
type: entity:{entity_type}

entity.entity_browser.add_form:
path: '/admin/config/content/entity_browser/add'
defaults:
_entity_wizard: 'entity_browser.add'
_title: 'Add Entity browser'
tempstore_id: 'entity_browser.config'
requirements:
_permission: 'administer entity browsers'

entity.entity_browser.edit_form:
path: '/admin/config/content/entity_browser/{machine_name}/{step}'
defaults:
_entity_wizard: 'entity_browser.edit'
_title: 'Edit Entity browser'
tempstore_id: 'entity_browser.config'
requirements:
_permission: 'administer entity browsers'

entity.entity_browser.collection:
path: '/admin/config/content/entity_browser'
defaults:
_entity_list: 'entity_browser'
_title: 'Entity Browsers'
requirements:
_permission: 'administer entity browsers'

entity.entity_browser.delete_form:
path: '/admin/config/content/entity_browser/{entity_browser}/delete'
defaults:
_entity_form: 'entity_browser.delete'
_title: 'Delete Entity browser'
requirements:
_permission: 'administer entity browsers'
5 changes: 5 additions & 0 deletions entity_browser.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ services:
entity_browser.route_subscriber:
class: Drupal\entity_browser\RouteSubscriber
arguments: ['@entity.manager', '@plugin.manager.entity_browser.display', '@entity.query']
entity_browser.ctools_fallback_route_enhancer:
class: Drupal\entity_browser\Routing\CtoolsFallbackRouteEnhancer
arguments: ['@module_handler']
tags:
- { name: route_enhancer }
29 changes: 29 additions & 0 deletions src/Controllers/CtoolsFallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\entity_browser\Controllers;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;

/**
* Returns markup for entity browser entity add/edit page if ctools is missing.
*/
class CtoolsFallback extends ControllerBase {

/**
* Displays message about missing dependency on edit/add page.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An Ajax response with a command for opening or closing the dialog
* containing the edit form.
*/
public function displayMessage() {
return [
'#markup' => $this->t(
'This form depends on <a href=":url">Chaos tool suite module</a>. Enable it and reload this page.',
[':url' => Url::fromUri('https://drupal.org/project/ctools')->toString()]
),
];
}

}
45 changes: 45 additions & 0 deletions src/Controllers/EntityBrowserListBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @file
* Contains \Drupal\entity_browser\Controllers\EntityBrowserListBuilder.
*/

namespace Drupal\entity_browser\Controllers;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;


/**
* Provides a list controller for entity browser.
*
* @ingroup entity_browser
*/
class EntityBrowserListBuilder extends EntityListBuilder {

/**
* {@inheritdoc}
*
* Building the header and content lines for the entity browser list.
*
* Calling the parent::buildHeader() adds a column for the possible actions
* and inserts the 'edit' and 'delete' links as defined for the entity type.
*/
public function buildHeader() {
$header['id'] = $this->t('ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}

/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\entity_browser\Entity\EntityBrowser */
$row['id'] = $entity->id();
$row['name'] = $entity->label();
return $row + parent::buildRow($entity);
}

}
7 changes: 6 additions & 1 deletion src/DisplayBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
abstract class DisplayBase extends PluginBase implements DisplayInterface, ContainerFactoryPluginInterface {

use PluginConfigurationFormTrait;

/**
* Plugin label.
*
Expand Down Expand Up @@ -78,7 +80,10 @@ public function defaultConfiguration() {
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
return array_diff_key(
$this->configuration,
['entity_browser_id' => 0]
);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/DisplayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;

/**
* Defines the interface for entity browser displays.
*/
interface DisplayInterface extends PluginInspectionInterface, ConfigurablePluginInterface {
interface DisplayInterface extends PluginInspectionInterface, ConfigurablePluginInterface, PluginFormInterface {

/**
* Returns the display label.
Expand Down
78 changes: 73 additions & 5 deletions src/Entity/EntityBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@
* label = @Translation("Entity browser"),
* handlers = {
* "form" = {
* "entity_browser" = "Drupal\entity_browser\Form\EntityBrowserForm"
* "entity_browser" = "Drupal\entity_browser\Form\EntityBrowserForm",
* "delete" = "Drupal\entity_browser\Form\EntityBrowserDeleteForm",
* },
* "access" = "Drupal\Core\Entity\EntityAccessControlHandler",
* "list_builder" = "Drupal\entity_browser\Controllers\EntityBrowserListBuilder",
* "wizard" = {
* "add" = "Drupal\entity_browser\Wizard\EntityBrowserWizardAdd",
* "edit" = "Drupal\entity_browser\Wizard\EntityBrowserWizard",
* }
* },
* links = {
* "canonical" = "/admin/config/content/entity_browser/{machine_name}/{step}",
* "collection" = "/admin/config/content/entity_browser",
* "edit-form" = "/admin/config/content/entity_browser/{machine_name}/{step}",
* "delete-form" = "/admin/config/content/entity_browser/{entity_browser}/delete",
* },
* admin_permission = "administer entity browsers",
* config_prefix = "browser",
* entity_keys = {
Expand Down Expand Up @@ -89,7 +102,7 @@ class EntityBrowser extends ConfigEntityBase implements EntityBrowserInterface,
*
* @var array
*/
protected $widgets;
protected $widgets = [];

/**
* Holds the collection of widgets that are used by this entity browser.
Expand Down Expand Up @@ -172,7 +185,7 @@ public function getName() {
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
$this->name = $name;
return $this;
}

Expand All @@ -183,6 +196,44 @@ public function getDisplay() {
return $this->displayPluginCollection()->get($this->display);
}

/**
* {@inheritdoc}
*/
public function setLabel($label) {
$this->label = $label;
return $this;
}

/**
* {@inheritdoc}
*/
public function setDisplay($display) {
$this->display = $display;
$this->displayPluginCollection = NULL;
$this->getDisplay();
return $this;
}

/**
* {@inheritdoc}
*/
public function setWidgetSelector($widget_selector) {
$this->widget_selector = $widget_selector;
$this->widgetSelectorCollection = NULL;
$this->getWidgetSelector();
return $this;
}

/**
* {@inheritdoc}
*/
public function setSelectionDisplay($selection_display) {
$this->selection_display = $selection_display;
$this->selectionDisplayCollection = NULL;
$this->getSelectionDisplay();
return $this;
}

/**
* Returns display plugin collection.
*
Expand Down Expand Up @@ -247,7 +298,7 @@ public function addWidget(array $configuration) {
* {@inheritdoc}
*/
public function deleteWidget(WidgetInterface $widget) {
$this->getWidgets()->removeInstanceId($widget->getUuid());
$this->getWidgets()->removeInstanceId($widget->uuid());
$this->save();
return $this;
}
Expand Down Expand Up @@ -371,7 +422,7 @@ public function __sleep() {
// Save configuration for all plugins.
$this->widgets = $this->getWidgets()->getConfiguration();
$this->widget_selector_configuration = $this->widgetSelectorPluginCollection()->getConfiguration();
$this->display_configuration = $this->widgetSelectorPluginCollection()->getConfiguration();
$this->display_configuration = $this->displayPluginCollection()->getConfiguration();
$this->selection_display_configuration = $this->selectionDisplayPluginCollection()->getConfiguration();

return array_diff(
Expand Down Expand Up @@ -406,4 +457,21 @@ public function getFormObject() {
return $form_class;
}

/**
* {@inheritdoc}
*/
protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel);

// Form wizard expects step argument and uses machine_name instead of
// entity_browser.
if ($rel == 'edit-form') {
$uri_route_parameters['step'] = 'general';
$uri_route_parameters['machine_name'] = $uri_route_parameters['entity_browser'];
unset($uri_route_parameters['entity_browser']);
}

return $uri_route_parameters;
}

}
Loading

0 comments on commit fbaab63

Please sign in to comment.