summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2014-04-10 03:17:40 (GMT)
committerwebchick2014-04-10 03:17:40 (GMT)
commitf97d2fa5a3d7a132341fa355f6ee018760b13229 (patch)
treeb9b4ab7b3d67f6848127394fe2425ebf5d1f3fc0
parent3c488c482ef77e9fd2f662a652916862bbb586bb (diff)
Issue #2236851 by alexpott | Berdir: Views blocks are missing dependency on view.
-rw-r--r--core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php5
-rw-r--r--core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php5
-rw-r--r--core/modules/views/lib/Drupal/views/Tests/Plugin/BlockDependenciesTest.php123
3 files changed, 133 insertions, 0 deletions
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 @@ class ViewsBlock implements ContainerDerivativeInterface {
$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 @@ class ViewsExposedFilterBlock implements ContainerDerivativeInterface {
$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 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\views\Tests\Plugin\BlockDependenciesTest.
+ */
+
+namespace Drupal\views\Tests\Plugin;
+
+use Drupal\views\Tests\ViewUnitTestBase;
+
+/**
+ * Tests exposed views derived blocks have the correct config dependencies.
+ */
+class BlockDependenciesTest extends ViewUnitTestBase {
+
+ /**
+ * Views used by this test.
+ *
+ * @var array
+ */
+ public static $testViews = array('test_exposed_block');
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('node', 'block');
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getInfo() {
+ return array(
+ 'name' => '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;
+ }
+
+}