Commit f97d2fa5 authored by webchick's avatar webchick

Issue #2236851 by alexpott | Berdir: Views blocks are missing dependency on view.

parent 3c488c48
......@@ -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;
}
......
......@@ -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;
}
......
<?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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment