diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php index c1d753b..be44dca 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php @@ -102,6 +102,11 @@ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives[$delta] = array( 'category' => $display->getOption('block_category'), 'admin_label' => $desc, + 'config_dependencies' => array( + 'entity' => array( + $view->getConfigDependencyName(), + ) + ) ); $this->derivatives[$delta] += $base_plugin_definition; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php index f077d8e..2dd5f69 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -93,6 +93,11 @@ public function getDerivativeDefinitions($base_plugin_definition) { $desc = t('Exposed form: @view-@display_id', array('@view' => $view->id(), '@display_id' => $display->display['id'])); $this->derivatives[$delta] = array( 'admin_label' => $desc, + 'config_dependencies' => array( + 'entity' => array( + $view->getConfigDependencyName(), + ) + ) ); $this->derivatives[$delta] += $base_plugin_definition; } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/BlockDependenciesTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/BlockDependenciesTest.php new file mode 100644 index 0000000..42db1e0 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/BlockDependenciesTest.php @@ -0,0 +1,123 @@ + 'Views block config dependencies', + 'description' => 'Test views block config dependencies functionality.', + 'group' => 'Views Plugins', + ); + } + + /** + * Tests that exposed filter blocks have the correct dependencies. + * + * @see \Drupal\views\Plugin\Derivative\ViewsExposedFilterBlock::getDerivativeDefinitions() + */ + public function testExposedBlock() { + $block = $this->createBlock('views_exposed_filter_block:test_exposed_block-page_1'); + $dependencies = $block->calculateDependencies(); + $expected = array( + 'entity' => array('views.view.test_exposed_block'), + 'module' => array('views'), + 'theme' => array('stark') + ); + $this->assertIdentical($expected, $dependencies); + } + + /** + * Tests that exposed filter blocks have the correct dependencies. + * + * @see \Drupal\views\Plugin\Derivative\ViewsBlock::getDerivativeDefinitions() + */ + public function testViewsBlock() { + $block = $this->createBlock('views_block:content_recent-block_1'); + $dependencies = $block->calculateDependencies(); + $expected = array( + 'entity' => array('views.view.content_recent'), + 'module' => array('views'), + 'theme' => array('stark') + ); + $this->assertIdentical($expected, $dependencies); + } + + /** + * Creates a block instance based on default settings. + * + * @param string $plugin_id + * The plugin ID of the block type for this block instance. + * @param array $settings + * (optional) An associative array of settings for the block entity. + * Override the defaults by specifying the key and value in the array, for + * example: + * @code + * $this->createBlock('system_powered_by_block', array( + * 'label' => t('Hello, world!'), + * )); + * @endcode + * The following defaults are provided: + * - label: Random string. + * - id: Random string. + * - region: 'sidebar_first'. + * - theme: The default theme. + * - visibility: Empty array. + * - cache: array('max_age' => 0). + * + * @return \Drupal\block\Entity\Block + * The block entity. + */ + protected function createBlock($plugin_id, array $settings = array()) { + $settings += array( + 'plugin' => $plugin_id, + 'region' => 'sidebar_first', + 'id' => strtolower($this->randomName(8)), + 'theme' => \Drupal::config('system.theme')->get('default'), + 'label' => $this->randomName(8), + 'visibility' => array(), + 'weight' => 0, + 'cache' => array( + 'max_age' => 0, + ), + ); + foreach (array('region', 'id', 'theme', 'plugin', 'visibility', 'weight') as $key) { + $values[$key] = $settings[$key]; + // Remove extra values that do not belong in the settings array. + unset($settings[$key]); + } + $values['settings'] = $settings; + $block = entity_create('block', $values); + $block->save(); + return $block; + } + +}