diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index ae7b56e..17e3d05 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -882,7 +882,7 @@ function field_langcode(EntityInterface $entity) { /** * {@inheritdoc} */ - public function getAdditionalDependencies() { + public function getDependencies() { // Add the module providing the configured field as a dependency. $field = FieldHelper::fieldInfo()->getField($this->definition['entity_type'], $this->definition['field_name']); return array($field->get('module')); diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index 8eea4c1..1596bf4 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -365,4 +365,34 @@ public function mergeDefaultDisplaysOptions() { $this->set('display', $displays); } + /** + * Returns an array of module dependencies for this view. + * + * These modules can depend on the configuration. + * + * @return array + */ + public function getDependencies() { + $handler_types = ViewExecutable::viewsHandlerTypes(); + $plugin_types = ViewExecutable::getPluginTypes(); + $dependencies = array(); + foreach ($this->get('display') as $display) { + // Collect all dependencies of handlers. + foreach ($handler_types as $type) { + if (isset($display['display_options'][$type['plural']])) { + foreach ($display['display_options'][$type['plural']] as $handler) { + $dependencies = array_merge($dependencies, $handler['dependencies']); + } + } + } + // Collect all dependencies of plugins. + foreach ($plugin_types as $plugin_type) { + if (isset($display['display_options'][$plugin_type]['options']['dependencies'])) { + $dependencies = array_merge($dependencies, $display['display_options'][$plugin_type]['options']['dependencies']); + } + } + } + return array_values(array_unique($dependencies)); + } + } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php index f79061c..e0f045f 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php @@ -424,11 +424,14 @@ public static function preRenderFlattenData($form) { } /** - * Returns an array of additional dependencies for this plugin. + * Returns an array of module dependencies for this plugin. + * + * Dependencies are a list of module names, which might depend on the + * configuration. * * @return array */ - public function getAdditionalDependencies() { + public function getDependencies() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/ViewStorageInterface.php b/core/modules/views/lib/Drupal/views/ViewStorageInterface.php index 089f428..5f4063b 100644 --- a/core/modules/views/lib/Drupal/views/ViewStorageInterface.php +++ b/core/modules/views/lib/Drupal/views/ViewStorageInterface.php @@ -29,4 +29,14 @@ public function &getDisplay($display_id); * Add defaults to the display options. */ public function mergeDefaultDisplaysOptions(); + + /** + * Returns an array of module dependencies for this view. + * + * These modules can depend on the configuration. + * + * @return array + */ + public function getDependencies(); + } diff --git a/core/modules/views/tests/Drupal/views/Tests/Entity/ViewTest.php b/core/modules/views/tests/Drupal/views/Tests/Entity/ViewTest.php index c8134f2..0ed2e2d 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Entity/ViewTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Entity/ViewTest.php @@ -5,9 +5,65 @@ * Contains \Drupal\views\Tests\Entity\ViewTest. */ -namespace Drupal\views\Tests\Entity; +namespace Drupal\views\Tests\Entity { -class ViewTest { +use Drupal\Tests\UnitTestCase; +use Drupal\views\Entity\View; + +/** + * Tests the view entity. + * + * @coversDefaultClass \Drupal\views\Entity\View + */ +class ViewTest extends UnitTestCase { + + /** + * Tests getting dependencies. + * + * @covers ::getDependencies + */ + public function testGetDependenciesWithNoDependencies() { + $values = array(); + $view = new View($values, 'view'); + $this->assertEquals(array(), $view->getDependencies()); + } + + /** + * Tests getting dependencies defined on some handlers. + */ + public function testGetDependenciesOnHandlers() { + $values = array(); + $values['display']['default']['display_options']['fields']['example']['dependencies'] = array(); + $values['display']['default']['display_options']['fields']['example2']['dependencies'] = array('views', 'field'); + $values['display']['default']['display_options']['fields']['example3']['dependencies'] = array('views', 'image'); + + $view = new View($values, 'view'); + $this->assertEquals(array('views', 'field', 'image'), $view->getDependencies()); + } + + /** + * Tests getting dependencies defined on some plugins. + */ + public function testGetDependenciesOnPlugins() { + $values = array(); + $values['display']['default']['display_options']['access']['options']['dependencies'] = array(); + $values['display']['default']['display_options']['row']['options']['dependencies'] = array('views', 'field'); + $values['display']['default']['display_options']['style']['options']['dependencies'] = array('views', 'image'); + + $view = new View($values, 'view'); + $this->assertEquals(array('views', 'field', 'image'), $view->getDependencies()); + } + +} } +namespace { + +if (!function_exists('t')) { + function t($string) { + return $string; + } +} + +} diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigHandler.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigHandler.php index d4388a2..3191a2e 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigHandler.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigHandler.php @@ -238,11 +238,13 @@ public function submitForm(array &$form, array &$form_state) { // extra stuff on the form is not sent through. $handler->unpackOptions($handler->options, $options, NULL, FALSE); - // Add any additional dependencies as the handler is saved. Put it here so + // Add any dependencies as the handler is saved. Put it here so // it does not need to be declared in defineOptions(). - if ($additional_dependencies = $handler->getAdditionalDependencies()) { - $handler->options['additional_dependencies'] = $additional_dependencies; + if ($dependencies = $handler->getDependencies()) { + $handler->options['dependencies'] = $dependencies; } + // Add the module providing the handler as dependency as well. + $handler->options['dependencies'][] = $handler->definition['provider']; // Store the item back on the view $executable->setHandler($form_state['display_id'], $form_state['type'], $form_state['id'], $handler->options);