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 be3734d..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 @@ -879,4 +879,14 @@ function field_langcode(EntityInterface $entity) { } } + /** + * {@inheritdoc} + */ + 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 aaae022..e0f045f 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php @@ -423,4 +423,16 @@ public static function preRenderFlattenData($form) { return $form; } + /** + * 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 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 new file mode 100644 index 0000000..0ed2e2d --- /dev/null +++ b/core/modules/views/tests/Drupal/views/Tests/Entity/ViewTest.php @@ -0,0 +1,69 @@ +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 c82cd07..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,6 +238,14 @@ 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 dependencies as the handler is saved. Put it here so + // it does not need to be declared in defineOptions(). + 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);