Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -88,10 +88,10 @@ class BlockAccessControlHandler extends EntityAccessControlHandler implements En
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\block\BlockInterface $entity */
|
||||
if ($operation != 'view') {
|
||||
return parent::checkAccess($entity, $operation, $langcode, $account);
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
|
||||
// Don't grant access to disabled blocks.
|
||||
|
|
|
@ -335,6 +335,12 @@ class BlockForm extends EntityForm {
|
|||
|
||||
// Call the plugin submit handler.
|
||||
$entity->getPlugin()->submitConfigurationForm($form, $settings);
|
||||
$block = $entity->getPlugin();
|
||||
// If this block is context-aware, set the context mapping.
|
||||
if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) {
|
||||
$context_mapping = $settings->getValue('context_mapping', []);
|
||||
$block->setContextMapping($context_mapping);
|
||||
}
|
||||
// Update the original form values.
|
||||
$form_state->setValue('settings', $settings->getValues());
|
||||
|
||||
|
|
|
@ -214,6 +214,11 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
),
|
||||
);
|
||||
$form['region-' . $region]['title'] = array(
|
||||
'#theme_wrappers' => array(
|
||||
'container' => array(
|
||||
'#attributes' => array('class' => 'region-title__action'),
|
||||
)
|
||||
),
|
||||
'#prefix' => $region != BlockInterface::BLOCK_REGION_NONE ? $title : $block_regions_with_disabled[$region],
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Place block <span class="visually-hidden">in the %region region</span>', ['%region' => $block_regions_with_disabled[$region]]),
|
||||
|
@ -256,7 +261,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
),
|
||||
);
|
||||
if ($placement && $placement == Html::getClass($entity_id)) {
|
||||
$form[$entity_id]['#attributes']['class'][] = 'color-warning';
|
||||
$form[$entity_id]['#attributes']['class'][] = 'color-success';
|
||||
$form[$entity_id]['#attributes']['class'][] = 'js-block-placed';
|
||||
}
|
||||
$form[$entity_id]['info'] = array(
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\block;
|
||||
|
||||
use Drupal\Core\Block\MainContentBlockPluginInterface;
|
||||
use Drupal\Core\Block\TitleBlockPluginInterface;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
|
@ -16,6 +17,7 @@ use Drupal\Core\Entity\EntityViewBuilder;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -63,7 +65,7 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) {
|
||||
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,12 +101,13 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
'tags' => $cache_tags,
|
||||
'max-age' => $plugin->getCacheMaxAge(),
|
||||
],
|
||||
'#weight' => $entity->getWeight(),
|
||||
);
|
||||
|
||||
// Allow altering of cacheability metadata or setting #create_placeholder.
|
||||
$this->moduleHandler->alter(['block_build', "block_build_" . $plugin->getBaseId()], $build[$entity_id], $plugin);
|
||||
|
||||
if ($plugin instanceof MainContentBlockPluginInterface) {
|
||||
if ($plugin instanceof MainContentBlockPluginInterface || $plugin instanceof TitleBlockPluginInterface) {
|
||||
// Immediately build a #pre_render-able block, since this block cannot
|
||||
// be built lazily.
|
||||
$build[$entity_id] += static::buildPreRenderableBlock($entity, $this->moduleHandler());
|
||||
|
@ -139,6 +142,12 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
$derivative_id = $plugin->getDerivativeId();
|
||||
$configuration = $plugin->getConfiguration();
|
||||
|
||||
// Inject runtime contexts.
|
||||
if ($plugin instanceof ContextAwarePluginInterface) {
|
||||
$contexts = \Drupal::service('context.repository')->getRuntimeContexts($plugin->getContextMapping());
|
||||
\Drupal::service('context.handler')->applyContextMapping($plugin, $contexts);
|
||||
}
|
||||
|
||||
// Create the render array for the block as a whole.
|
||||
// @see template_preprocess_block().
|
||||
$build = [
|
||||
|
@ -183,7 +192,7 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
* @return array
|
||||
* A render array with a #pre_render callback to render the block.
|
||||
*/
|
||||
public static function lazyBuilder($entity_id, $view_mode, $langcode) {
|
||||
public static function lazyBuilder($entity_id, $view_mode) {
|
||||
return static::buildPreRenderableBlock(entity_load('block', $entity_id), \Drupal::service('module_handler'));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Extension\ThemeHandler;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
|
@ -55,7 +56,7 @@ class BlockController extends ControllerBase {
|
|||
*/
|
||||
public function demo($theme) {
|
||||
$page = [
|
||||
'#title' => $this->themeHandler->getName($theme),
|
||||
'#title' => Html::escape($this->themeHandler->getName($theme)),
|
||||
'#type' => 'page',
|
||||
'#attached' => array(
|
||||
'drupalSettings' => [
|
||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\Core\Block\BlockManagerInterface;
|
|||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\Core\Menu\LocalActionManagerInterface;
|
||||
use Drupal\Core\Plugin\Context\LazyContextRepository;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -29,6 +30,13 @@ class BlockLibraryController extends ControllerBase {
|
|||
*/
|
||||
protected $blockManager;
|
||||
|
||||
/**
|
||||
* The context repository.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\Context\LazyContextRepository
|
||||
*/
|
||||
protected $contextRepository;
|
||||
|
||||
/**
|
||||
* The route match.
|
||||
*
|
||||
|
@ -48,15 +56,18 @@ class BlockLibraryController extends ControllerBase {
|
|||
*
|
||||
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
|
||||
* The block manager.
|
||||
* @param \Drupal\Core\Plugin\Context\LazyContextRepository $context_repository
|
||||
* The context repository.
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The current route match.
|
||||
* @param \Drupal\Core\Menu\LocalActionManagerInterface $local_action_manager
|
||||
* The local action manager.
|
||||
*/
|
||||
public function __construct(BlockManagerInterface $block_manager, RouteMatchInterface $route_match, LocalActionManagerInterface $local_action_manager) {
|
||||
public function __construct(BlockManagerInterface $block_manager, LazyContextRepository $context_repository, RouteMatchInterface $route_match, LocalActionManagerInterface $local_action_manager) {
|
||||
$this->blockManager = $block_manager;
|
||||
$this->routeMatch = $route_match;
|
||||
$this->localActionManager = $local_action_manager;
|
||||
$this->contextRepository = $context_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,6 +76,7 @@ class BlockLibraryController extends ControllerBase {
|
|||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('plugin.manager.block'),
|
||||
$container->get('context.repository'),
|
||||
$container->get('current_route_match'),
|
||||
$container->get('plugin.manager.menu.local_action')
|
||||
);
|
||||
|
@ -95,7 +107,7 @@ class BlockLibraryController extends ControllerBase {
|
|||
];
|
||||
|
||||
// Only add blocks which work without any available context.
|
||||
$definitions = $this->blockManager->getDefinitionsForContexts();
|
||||
$definitions = $this->blockManager->getDefinitionsForContexts($this->contextRepository->getAvailableContexts());
|
||||
// Order by category, and then by admin label.
|
||||
$definitions = $this->blockManager->getSortedDefinitions($definitions);
|
||||
|
||||
|
@ -104,9 +116,11 @@ class BlockLibraryController extends ControllerBase {
|
|||
foreach ($definitions as $plugin_id => $plugin_definition) {
|
||||
$row = [];
|
||||
$row['title']['data'] = [
|
||||
'#markup' => $plugin_definition['admin_label'],
|
||||
'#prefix' => '<div class="block-filter-text-source">',
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<div class="block-filter-text-source">{{ label }}</div>',
|
||||
'#context' => [
|
||||
'label' => $plugin_definition['admin_label'],
|
||||
],
|
||||
];
|
||||
$row['category']['data'] = $plugin_definition['category'];
|
||||
$links['add'] = [
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
@ -59,7 +59,7 @@ class CategoryAutocompleteController implements ContainerInjectionInterface {
|
|||
$matches = array();
|
||||
foreach ($this->blockManager->getCategories() as $category) {
|
||||
if (stripos($category, $typed_category) === 0) {
|
||||
$matches[] = array('value' => $category, 'label' => SafeMarkup::checkPlain($category));
|
||||
$matches[] = array('value' => $category, 'label' => Html::escape($category));
|
||||
}
|
||||
}
|
||||
return new JsonResponse($matches);
|
||||
|
|
|
@ -231,7 +231,7 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
|||
public function calculateDependencies() {
|
||||
parent::calculateDependencies();
|
||||
$this->addDependency('theme', $this->theme);
|
||||
return $this->dependencies;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\block\Plugin\DisplayVariant;
|
|||
|
||||
use Drupal\block\BlockRepositoryInterface;
|
||||
use Drupal\Core\Block\MainContentBlockPluginInterface;
|
||||
use Drupal\Core\Block\TitleBlockPluginInterface;
|
||||
use Drupal\Core\Block\MessagesBlockPluginInterface;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Display\PageVariantInterface;
|
||||
|
@ -63,6 +64,13 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
|
|||
*/
|
||||
protected $mainContent = [];
|
||||
|
||||
/**
|
||||
* The page title: a string (plain title) or a render array (formatted title).
|
||||
*
|
||||
* @var string|array
|
||||
*/
|
||||
protected $title = '';
|
||||
|
||||
/**
|
||||
* Constructs a new BlockPageVariant.
|
||||
*
|
||||
|
@ -108,6 +116,14 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -131,6 +147,9 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
|
|||
$block_plugin->setMainContent($this->mainContent);
|
||||
$main_content_block_displayed = TRUE;
|
||||
}
|
||||
elseif ($block_plugin instanceof TitleBlockPluginInterface) {
|
||||
$block_plugin->setTitle($this->title);
|
||||
}
|
||||
elseif ($block_plugin instanceof MessagesBlockPluginInterface) {
|
||||
$messages_block_displayed = TRUE;
|
||||
}
|
||||
|
@ -138,8 +157,9 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
|
|||
|
||||
// The main content block cannot be cached: it is a placeholder for the
|
||||
// render array returned by the controller. It should be rendered as-is,
|
||||
// with other placed blocks "decorating" it.
|
||||
if ($block_plugin instanceof MainContentBlockPluginInterface) {
|
||||
// with other placed blocks "decorating" it. Analogous reasoning for the
|
||||
// title block.
|
||||
if ($block_plugin instanceof MainContentBlockPluginInterface || $block_plugin instanceof TitleBlockPluginInterface) {
|
||||
unset($build[$region][$key]['#cache']['keys']);
|
||||
}
|
||||
}
|
||||
|
@ -165,6 +185,12 @@ class BlockPageVariant extends VariantBase implements PageVariantInterface, Cont
|
|||
];
|
||||
}
|
||||
|
||||
// If any render arrays are manually placed, render arrays and blocks must
|
||||
// be sorted.
|
||||
if (!$main_content_block_displayed || !$messages_block_displayed) {
|
||||
unset($build['content']['#sorted']);
|
||||
}
|
||||
|
||||
// The access results' cacheability is currently added to the top level of the
|
||||
// render array. This is done to prevent issues with empty regions being
|
||||
// displayed.
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\destination\EntityBlock.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateDestination(
|
||||
* id = "entity:block"
|
||||
* )
|
||||
*/
|
||||
class EntityBlock extends EntityConfigBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEntityId(Row $row) {
|
||||
// Try to find the block by its plugin ID and theme.
|
||||
$properties = array(
|
||||
'plugin' => $row->getDestinationProperty('plugin'),
|
||||
'theme' => $row->getDestinationProperty('theme'),
|
||||
);
|
||||
$blocks = array_keys($this->storage->loadByProperties($properties));
|
||||
return reset($blocks);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,34 +2,38 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockPluginId.
|
||||
* Contains \Drupal\block\Plugin\migrate\process\BlockPluginId.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process\d6;
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_block_plugin_id"
|
||||
* id = "block_plugin_id"
|
||||
* )
|
||||
*/
|
||||
class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigratePluginManager
|
||||
* The migration process plugin, configured for lookups in d6_custom_block
|
||||
* and d7_custom_block.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*/
|
||||
protected $processPluginManager;
|
||||
protected $migrationPlugin;
|
||||
|
||||
/**
|
||||
* The block_content entity storage handler.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $blockContentStorage;
|
||||
|
@ -37,11 +41,10 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, MigratePluginManager $process_plugin_manager) {
|
||||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, MigrateProcessInterface $migration_plugin) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->blockContentStorage = $storage;
|
||||
$this->migration = $migration;
|
||||
$this->processPluginManager = $process_plugin_manager;
|
||||
$this->migrationPlugin = $migration_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,13 +52,18 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
|
|||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
$migration_configuration = array(
|
||||
'migration' => array(
|
||||
'd6_custom_block',
|
||||
'd7_custom_block',
|
||||
),
|
||||
);
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$entity_manager->getDefinition('block_content') ? $entity_manager->getStorage('block_content') : NULL,
|
||||
$container->get('plugin.manager.migrate.process')
|
||||
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -70,31 +78,28 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
|
|||
switch ($module) {
|
||||
case 'aggregator':
|
||||
list($type, $id) = explode('-', $delta);
|
||||
if ($type == 'category') {
|
||||
// @TODO skip row.
|
||||
// throw new MigrateSkipRowException();
|
||||
if ($type == 'feed') {
|
||||
return 'aggregator_feed_block';
|
||||
}
|
||||
$value = 'aggregator_feed_block';
|
||||
break;
|
||||
case 'menu':
|
||||
$value = "system_menu_block:$delta";
|
||||
break;
|
||||
return "system_menu_block:$delta";
|
||||
case 'block':
|
||||
if ($this->blockContentStorage) {
|
||||
$block_ids = $this->processPluginManager
|
||||
->createInstance('migration', array('migration' => 'd6_custom_block'), $this->migration)
|
||||
$block_id = $this->migrationPlugin
|
||||
->transform($delta, $migrate_executable, $row, $destination_property);
|
||||
$value = 'block_content:' . $this->blockContentStorage->load($block_ids[0])->uuid();
|
||||
}
|
||||
else {
|
||||
throw new MigrateSkipRowException();
|
||||
if ($block_id) {
|
||||
return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new MigrateSkipRowException();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\BlockRegion.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "block_region"
|
||||
* )
|
||||
*/
|
||||
class BlockRegion extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* List of regions, keyed by theme.
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
protected $regions;
|
||||
|
||||
/**
|
||||
* Constructs a BlockRegion plugin instance.
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin configuration.
|
||||
* @param string $plugin_id
|
||||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param array $regions
|
||||
* Array of region maps, keyed by theme.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, array $regions) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->regions = $regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
$regions = array();
|
||||
foreach ($container->get('theme_handler')->listInfo() as $key => $theme) {
|
||||
$regions[$key] = $theme->info['regions'];
|
||||
}
|
||||
return new static($configuration, $plugin_id, $plugin_definition, $regions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
// Set the destination region, based on the source region and theme as well
|
||||
// as the current destination default theme.
|
||||
list($region, $source_theme, $destination_theme) = $value;
|
||||
|
||||
// Theme is the same on both source and destination, so ensure that the
|
||||
// region exists in the destination theme.
|
||||
if (strtolower($source_theme) == strtolower($destination_theme)) {
|
||||
if (isset($this->regions[$destination_theme][$region])) {
|
||||
return $region;
|
||||
}
|
||||
}
|
||||
|
||||
// If the source and destination theme are different, try to use the
|
||||
// mappings defined in the configuration.
|
||||
$region_map = $this->configuration['region_map'];
|
||||
if (isset($region_map[$region])) {
|
||||
return $region_map[$region];
|
||||
}
|
||||
|
||||
// Oh well, we tried. Put the block in the main content region.
|
||||
return 'content';
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockSettings.
|
||||
* Contains \Drupal\block\Plugin\migrate\process\BlockSettings.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process\d6;
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
|
@ -13,7 +13,7 @@ use Drupal\migrate\Row;
|
|||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_block_settings"
|
||||
* id = "block_settings"
|
||||
* )
|
||||
*/
|
||||
class BlockSettings extends ProcessPluginBase {
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockTheme.
|
||||
* Contains \Drupal\block\Plugin\migrate\process\BlockTheme.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process\d6;
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_block_theme"
|
||||
* id = "block_theme"
|
||||
* )
|
||||
*/
|
||||
class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
@ -74,11 +74,9 @@ class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInte
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Set the block theme, based on the current default theme.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($theme, $d6_default_theme, $d6_admin_theme) = $value;
|
||||
list($theme, $default_theme, $admin_theme) = $value;
|
||||
|
||||
// If the source theme exists on the destination, we're good.
|
||||
if (isset($this->themes[$theme])) {
|
||||
|
@ -87,13 +85,13 @@ class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInte
|
|||
|
||||
// If the source block is assigned to a region in the source default theme,
|
||||
// then assign it to the destination default theme.
|
||||
if (strtolower($theme) == strtolower($d6_default_theme)) {
|
||||
if (strtolower($theme) == strtolower($default_theme)) {
|
||||
return $this->themeConfig->get('default');
|
||||
}
|
||||
|
||||
// If the source block is assigned to a region in the source admin theme,
|
||||
// then assign it to the destination admin theme.
|
||||
if (strtolower($theme) == strtolower($d6_admin_theme)) {
|
||||
if (strtolower($theme) == strtolower($admin_theme)) {
|
||||
return $this->themeConfig->get('admin');
|
||||
}
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\BlockVisibility.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "block_visibility"
|
||||
* )
|
||||
*/
|
||||
class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The migration process plugin, configured for lookups in the d6_user_role
|
||||
* and d7_user_role migrations.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*/
|
||||
protected $migrationPlugin;
|
||||
|
||||
/**
|
||||
* Whether or not to skip blocks that use PHP for visibility. Only applies
|
||||
* if the PHP module is not enabled.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $skipPHP = FALSE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, MigrateProcessInterface $migration_plugin) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->migrationPlugin = $migration_plugin;
|
||||
|
||||
if (isset($configuration['skip_php'])) {
|
||||
$this->skipPHP = $configuration['skip_php'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
$migration_configuration = array(
|
||||
'migration' => array(
|
||||
'd6_user_role',
|
||||
'd7_user_role',
|
||||
),
|
||||
);
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('module_handler'),
|
||||
$container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($old_visibility, $pages, $roles) = $value;
|
||||
|
||||
$visibility = array();
|
||||
|
||||
// If the block is assigned to specific roles, add the user_role condition.
|
||||
if ($roles) {
|
||||
$visibility['user_role'] = array(
|
||||
'id' => 'user_role',
|
||||
'roles' => array(),
|
||||
'context_mapping' => array(
|
||||
'user' => '@user.current_user_context:current_user',
|
||||
),
|
||||
'negate' => FALSE,
|
||||
);
|
||||
|
||||
foreach ($roles as $key => $role_id) {
|
||||
$roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
|
||||
}
|
||||
$visibility['user_role']['roles'] = array_combine($roles, $roles);
|
||||
}
|
||||
|
||||
if ($pages) {
|
||||
// 2 == BLOCK_VISIBILITY_PHP in Drupal 6 and 7.
|
||||
if ($old_visibility == 2) {
|
||||
// If the PHP module is present, migrate the visibility code unaltered.
|
||||
if ($this->moduleHandler->moduleExists('php')) {
|
||||
$visibility['php'] = array(
|
||||
'id' => 'php',
|
||||
// PHP code visibility could not be negated in Drupal 6 or 7.
|
||||
'negate' => FALSE,
|
||||
'php' => $pages,
|
||||
);
|
||||
}
|
||||
// Skip the row if we're configured to. If not, we don't need to do
|
||||
// anything else -- the block will simply have no PHP or request_path
|
||||
// visibility configuration.
|
||||
elseif ($this->skipPHP) {
|
||||
throw new MigrateSkipRowException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$paths = preg_split("(\r\n?|\n)", $pages);
|
||||
foreach ($paths as $key => $path) {
|
||||
$paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
|
||||
}
|
||||
$visibility['request_path'] = array(
|
||||
'id' => 'request_path',
|
||||
'negate' => !$old_visibility,
|
||||
'pages' => implode("\n", $paths),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $visibility;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockRegion.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_block_region"
|
||||
* )
|
||||
*/
|
||||
class BlockRegion extends ProcessPluginBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Set the destination block region, based on the source region and theme as
|
||||
* well as the current destination default theme.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($region, $source_theme, $destination_theme) = $value;
|
||||
|
||||
// Theme is the same on both source and destination, we will assume they
|
||||
// have the same regions.
|
||||
if (strtolower($source_theme) == strtolower($destination_theme)) {
|
||||
return $region;
|
||||
}
|
||||
|
||||
// If the source and destination theme are different, try to use the
|
||||
// mappings defined in the configuration.
|
||||
$region_map = $this->configuration['region_map'];
|
||||
if (isset($region_map[$region])) {
|
||||
return $region_map[$region];
|
||||
}
|
||||
|
||||
// Oh well, we tried. Put the block in the main content region.
|
||||
return 'content';
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\process\d6\BlockVisibility.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "d6_block_visibility"
|
||||
* )
|
||||
*/
|
||||
class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The migration plugin.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*/
|
||||
protected $migrationPlugin;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrateProcessInterface $migration_plugin) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->migration = $migration;
|
||||
$this->migrationPlugin = $migration_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('plugin.manager.migrate.process')->createInstance('migration', array('migration' => 'd6_user_role'), $migration)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Set the block visibility settings.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($pages, $roles, $old_visibility) = $value;
|
||||
$visibility = array();
|
||||
|
||||
if (!empty($pages)) {
|
||||
$visibility['request_path']['pages'] = $pages;
|
||||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = !$old_visibility;
|
||||
}
|
||||
|
||||
if (!empty($roles)) {
|
||||
foreach ($roles as $key => $role_id) {
|
||||
$new_role = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
|
||||
$visibility['user_role']['roles'][$new_role] = $new_role;
|
||||
}
|
||||
$visibility['user_role']['id'] = 'user_role';
|
||||
$visibility['user_role']['context_mapping']['user'] = 'user.current_user';
|
||||
}
|
||||
return $visibility;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,22 +2,24 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Plugin\migrate\source\d6\Block.
|
||||
* Contains \Drupal\block\Plugin\migrate\source\Block.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Plugin\migrate\source\d6;
|
||||
namespace Drupal\block\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 block source from database.
|
||||
* Drupal block source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_block"
|
||||
* id = "block",
|
||||
* source_provider = "block"
|
||||
* )
|
||||
*/
|
||||
class Block extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* The default theme name.
|
||||
*
|
||||
|
@ -32,14 +34,33 @@ class Block extends DrupalSqlBase {
|
|||
*/
|
||||
protected $adminTheme;
|
||||
|
||||
/**
|
||||
* Table containing block configuration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $blockTable;
|
||||
|
||||
/**
|
||||
* Table mapping blocks to user roles.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $blockRoleTable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('blocks', 'b')
|
||||
->fields('b', array('bid', 'module', 'delta', 'theme', 'status', 'weight', 'region', 'visibility', 'pages', 'title', 'cache'))
|
||||
->orderBy('bid');
|
||||
return $query;
|
||||
if ($this->getModuleSchemaVersion('system') >= 7000) {
|
||||
$this->blockTable = 'block';
|
||||
$this->blockRoleTable = 'block_role';
|
||||
}
|
||||
else {
|
||||
$this->blockTable = 'blocks';
|
||||
$this->blockRoleTable = 'blocks_roles';
|
||||
}
|
||||
return $this->select($this->blockTable, 'b')->fields('b');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,36 +88,54 @@ class Block extends DrupalSqlBase {
|
|||
'pages' => $this->t('Pages list.'),
|
||||
'title' => $this->t('Block title.'),
|
||||
'cache' => $this->t('Cache rule.'),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['module']['type'] = 'string';
|
||||
$ids['delta']['type'] = 'string';
|
||||
$ids['theme']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$row->setSourceProperty('default_theme', $this->defaultTheme);
|
||||
$row->setSourceProperty('admin_theme', $this->adminTheme);
|
||||
|
||||
$module = $row->getSourceProperty('module');
|
||||
$delta = $row->getSourceProperty('delta');
|
||||
$roles = $this->select('blocks_roles', 'br')
|
||||
|
||||
$roles = $this->select($this->blockRoleTable, 'br')
|
||||
->fields('br', array('rid'))
|
||||
->condition('module', $module)
|
||||
->condition('delta', $delta)
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('roles', $roles);
|
||||
|
||||
$settings = array();
|
||||
// Contrib can use hook_migration_d6_block_prepare_row() to add similar
|
||||
// variables via $migration->getSource()->variableGet().
|
||||
switch ($module) {
|
||||
case 'aggregator':
|
||||
list($type, $id) = explode('-', $delta);
|
||||
if ($type == 'feed') {
|
||||
$item_count = $this->database->query('SELECT block FROM {aggregator_feed} WHERE fid = :fid', array(':fid' => $id))->fetchField();
|
||||
$item_count = $this->select('aggregator_feed', 'af')
|
||||
->fields('af', ['block'])
|
||||
->condition('fid', $id)
|
||||
->execute()
|
||||
->fetchField();
|
||||
}
|
||||
else {
|
||||
$item_count = $this->database->query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField();
|
||||
$item_count = $this->select('aggregator_category', 'ac')
|
||||
->fields('ac', ['block'])
|
||||
->condition('cid', $id)
|
||||
->execute()
|
||||
->fetchField();
|
||||
}
|
||||
$settings['aggregator']['item_count'] = $item_count;
|
||||
break;
|
||||
|
@ -114,9 +153,11 @@ class Block extends DrupalSqlBase {
|
|||
case 'user':
|
||||
switch ($delta) {
|
||||
case 2:
|
||||
case 'new':
|
||||
$settings['user']['block_whois_new_count'] = $this->variableGet('user_block_whois_new_count', 5);
|
||||
break;
|
||||
case 3:
|
||||
case 'online':
|
||||
$settings['user']['block_seconds_online'] = $this->variableGet('user_block_seconds_online', 900);
|
||||
$settings['user']['max_list_count'] = $this->variableGet('user_block_max_list_count', 10);
|
||||
break;
|
||||
|
@ -126,14 +167,5 @@ class Block extends DrupalSqlBase {
|
|||
$row->setSourceProperty('settings', $settings);
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['module']['type'] = 'string';
|
||||
$ids['delta']['type'] = 'string';
|
||||
$ids['theme']['type'] = 'string';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ class BlockAdminThemeTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = array('block', 'contextual');
|
||||
|
||||
/**
|
||||
* Check for the accessibility of the admin theme on the block admin page.
|
||||
|
@ -43,4 +43,40 @@ class BlockAdminThemeTest extends WebTestBase {
|
|||
$this->drupalGet('admin/structure/block/list/bartik');
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure contextual links are disabled in Seven theme.
|
||||
*/
|
||||
function testSevenAdminTheme() {
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
'administer themes',
|
||||
'access contextual links',
|
||||
'view the administration theme',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Install admin theme and confirm that tab is accessible.
|
||||
\Drupal::service('theme_handler')->install(['seven']);
|
||||
$edit['admin_theme'] = 'seven';
|
||||
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
|
||||
|
||||
// Define our block settings.
|
||||
$settings = [
|
||||
'theme' => 'seven',
|
||||
'region' => 'header',
|
||||
];
|
||||
|
||||
// Place a block.
|
||||
$block = $this->drupalPlaceBlock('local_tasks_block', $settings);
|
||||
|
||||
// Open admin page.
|
||||
$this->drupalGet('admin');
|
||||
|
||||
// Check if contextual link classes are unavailable.
|
||||
$this->assertNoRaw('<div data-contextual-id="block:block=' . $block->id() . ':langcode=en"></div>');
|
||||
$this->assertNoRaw('contextual-region');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,9 +148,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
* Test non-cacheable block.
|
||||
*/
|
||||
function testNoCache() {
|
||||
$this->setBlockCacheConfig(array(
|
||||
'max_age' => 0,
|
||||
));
|
||||
\Drupal::state()->set('block_test.cache_max_age', 0);
|
||||
|
||||
$current_content = $this->randomMachineName();
|
||||
\Drupal::state()->set('block_test.content', $current_content);
|
||||
|
@ -219,13 +217,4 @@ class BlockCacheTest extends WebTestBase {
|
|||
$this->assertText($old_content, 'Block content cached for the test page.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method to set the test block's cache configuration.
|
||||
*/
|
||||
private function setBlockCacheConfig($cache_config) {
|
||||
$block = $this->block->getPlugin();
|
||||
$block->setConfigurationValue('cache', $cache_config);
|
||||
$this->block->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\block\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\block\BlockInterface;
|
||||
|
@ -44,9 +43,6 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
'label' => 'Custom Display Message',
|
||||
'provider' => 'block_test',
|
||||
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
'cache' => array(
|
||||
'max_age' => Cache::PERMANENT,
|
||||
),
|
||||
'display_message' => 'no message set',
|
||||
);
|
||||
// Initial configuration of the block at construction time.
|
||||
|
@ -60,10 +56,6 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
$this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block configuration was updated correctly.');
|
||||
$definition = $display_block->getPluginDefinition();
|
||||
|
||||
$period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400);
|
||||
$period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period));
|
||||
$period[0] = '<' . t('no caching') . '>';
|
||||
$period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever');
|
||||
$expected_form = array(
|
||||
'provider' => array(
|
||||
'#type' => 'value',
|
||||
|
@ -87,17 +79,7 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
'#default_value' => TRUE,
|
||||
'#return_value' => 'visible',
|
||||
),
|
||||
'cache' => array(
|
||||
'#type' => 'details',
|
||||
'#title' => t('Cache settings'),
|
||||
'max_age' => array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Maximum age'),
|
||||
'#description' => t('The maximum time this block may be cached.'),
|
||||
'#default_value' => Cache::PERMANENT,
|
||||
'#options' => $period,
|
||||
),
|
||||
),
|
||||
'context_mapping' => array(),
|
||||
'display_message' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Display message'),
|
||||
|
@ -109,7 +91,7 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
$actual_form = $display_block->buildConfigurationForm(array(), $form_state);
|
||||
// Remove the visibility sections, as that just tests condition plugins.
|
||||
unset($actual_form['visibility'], $actual_form['visibility_tabs']);
|
||||
$this->assertIdentical($actual_form, $expected_form, 'Only the expected form elements were present.');
|
||||
$this->assertIdentical($this->castSafeStrings($actual_form), $this->castSafeStrings($expected_form), 'Only the expected form elements were present.');
|
||||
|
||||
$expected_build = array(
|
||||
'#children' => 'My custom display message.',
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\block\Tests;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
use Drupal\block_test\Plugin\Block\TestHtmlBlock;
|
||||
|
@ -99,9 +98,6 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
'label' => '',
|
||||
'provider' => 'block_test',
|
||||
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
'cache' => array(
|
||||
'max_age' => Cache::PERMANENT,
|
||||
),
|
||||
),
|
||||
'visibility' => array(),
|
||||
);
|
||||
|
|
|
@ -135,6 +135,9 @@ class BlockTest extends BlockTestBase {
|
|||
* Test configuring and moving a module-define block to specific regions.
|
||||
*/
|
||||
function testBlock() {
|
||||
// Place page title block to test error messages.
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Select the 'Powered by Drupal' block to be configured and moved.
|
||||
$block = array();
|
||||
$block['id'] = 'system_powered_by_block';
|
||||
|
|
|
@ -86,6 +86,10 @@ class BlockUiTest extends WebTestBase {
|
|||
$this->clickLink(t('Demonstrate block regions (@theme)', array('@theme' => 'Classy')));
|
||||
$elements = $this->xpath('//div[contains(@class, "region-highlighted")]/div[contains(@class, "block-region") and contains(text(), :title)]', array(':title' => 'Highlighted'));
|
||||
$this->assertTrue(!empty($elements), 'Block demo regions are shown.');
|
||||
|
||||
\Drupal::service('theme_handler')->install(array('test_theme'));
|
||||
$this->drupalGet('admin/structure/block/demo/test_theme');
|
||||
$this->assertEscaped('<strong>Test theme</strong>');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,21 +166,57 @@ class BlockUiTest extends WebTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests the behavior of context-aware blocks.
|
||||
* Tests the behavior of unsatisfied context-aware blocks.
|
||||
*/
|
||||
public function testContextAwareBlocks() {
|
||||
public function testContextAwareUnsatisfiedBlocks() {
|
||||
$arguments = array(
|
||||
':ul_class' => 'block-list',
|
||||
':li_class' => 'test-context-aware',
|
||||
':href' => 'admin/structure/block/add/test_context_aware/classy',
|
||||
':text' => 'Test context-aware block',
|
||||
':category' => 'Block test',
|
||||
':href' => 'admin/structure/block/add/test_context_aware_unsatisfied/classy',
|
||||
':text' => 'Test context-aware unsatisfied block',
|
||||
);
|
||||
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$elements = $this->xpath('//details[@id="edit-category-block-test"]//ul[contains(@class, :ul_class)]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$elements = $this->xpath('//tr[.//td/div[text()=:text] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]', $arguments);
|
||||
$this->assertTrue(empty($elements), 'The context-aware test block does not appear.');
|
||||
|
||||
$definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware_unsatisfied');
|
||||
$this->assertTrue(!empty($definition), 'The context-aware test block does not exist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the behavior of context-aware blocks.
|
||||
*/
|
||||
public function testContextAwareBlocks() {
|
||||
$expected_text = '<div id="test_context_aware--username">' . \Drupal::currentUser()->getUsername() . '</div>';
|
||||
$this->drupalGet('');
|
||||
$this->assertNoText('Test context-aware block');
|
||||
$this->assertNoRaw($expected_text);
|
||||
|
||||
$block_url = 'admin/structure/block/add/test_context_aware/classy';
|
||||
$arguments = array(
|
||||
':title' => 'Test context-aware block',
|
||||
':category' => 'Block test',
|
||||
':href' => $block_url,
|
||||
);
|
||||
$pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]';
|
||||
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$elements = $this->xpath($pattern, $arguments);
|
||||
$this->assertTrue(!empty($elements), 'The context-aware test block appears.');
|
||||
$definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware');
|
||||
$this->assertTrue(!empty($definition), 'The context-aware test block exists.');
|
||||
|
||||
$edit = [
|
||||
'region' => 'content',
|
||||
'settings[context_mapping][user]' => '@block_test.multiple_static_context:user2',
|
||||
];
|
||||
$this->drupalPostForm($block_url, $edit, 'Save block');
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->assertText('Test context-aware block');
|
||||
$this->assertRaw($expected_text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,12 +26,23 @@ class BlockXssTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'block_test', 'menu_ui', 'views'];
|
||||
public static $modules = ['block', 'block_content', 'menu_ui', 'views'];
|
||||
|
||||
/**
|
||||
* Test XSS in title.
|
||||
* Tests that nothing is escaped other than the blocks explicitly tested.
|
||||
*/
|
||||
public function testNoUnexpectedEscaping() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'access administration pages']));
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->assertNoEscaped('<');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests XSS in title.
|
||||
*/
|
||||
public function testXssInTitle() {
|
||||
$this->container->get('module_installer')->install(['block_test']);
|
||||
$this->drupalPlaceBlock('test_xss_title', ['label' => '<script>alert("XSS label");</script>']);
|
||||
|
||||
\Drupal::state()->set('block_test.content', $this->randomMachineName());
|
||||
|
@ -48,6 +59,7 @@ class BlockXssTest extends WebTestBase {
|
|||
* Tests XSS in category.
|
||||
*/
|
||||
public function testXssInCategory() {
|
||||
$this->container->get('module_installer')->install(['block_test']);
|
||||
$this->drupalPlaceBlock('test_xss_title');
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'access administration pages']));
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
|
@ -64,24 +76,60 @@ class BlockXssTest extends WebTestBase {
|
|||
$this->doViewTest();
|
||||
$this->doMenuTest();
|
||||
$this->doBlockContentTest();
|
||||
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->assertNoRaw('&lt;', 'The page does not have double escaped HTML tags.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests XSS coming from View block labels.
|
||||
*/
|
||||
protected function doViewTest() {
|
||||
// Create a View without a custom label for its block Display. The
|
||||
// admin_label of the block then becomes just the View's label.
|
||||
$view = View::create([
|
||||
'id' => $this->randomMachineName(),
|
||||
'label' => '<script>alert("view");</script>',
|
||||
'label' => '<script>alert("view1");</script>',
|
||||
]);
|
||||
$view->addDisplay('block');
|
||||
$view->save();
|
||||
|
||||
// Create a View with a custom label for its block Display. The
|
||||
// admin_label of the block then becomes the View's label combined with
|
||||
// the Display's label.
|
||||
$view = View::create([
|
||||
'id' => $this->randomMachineName(),
|
||||
'label' => '<script>alert("view2");</script>',
|
||||
]);
|
||||
$view->addDisplay('block', 'Fish & chips');
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
// The block admin label is automatically XSS admin filtered.
|
||||
$this->assertRaw('alert("view");');
|
||||
$this->assertNoRaw('<script>alert("view");</script>');
|
||||
|
||||
// \Drupal\views\Plugin\Derivative\ViewsBlock::getDerivativeDefinitions()
|
||||
// has a different code path for an admin label based only on the View
|
||||
// label versus one based on both the View label and the Display label.
|
||||
// Ensure that this test is covering both code paths by asserting the
|
||||
// absence of a ":" for the first View and the presence of a ":" for the
|
||||
// second one. Note that the second assertion is redundant with the one
|
||||
// further down which also checks for the Display label, but is included
|
||||
// here for clarity.
|
||||
$this->assertNoEscaped('<script>alert("view1");</script>:');
|
||||
$this->assertEscaped('<script>alert("view2");</script>:');
|
||||
|
||||
// Assert that the blocks have their admin labels escaped and
|
||||
// don't appear anywhere unescaped.
|
||||
$this->assertEscaped('<script>alert("view1");</script>');
|
||||
$this->assertNoRaw('<script>alert("view1");</script>');
|
||||
$this->assertEscaped('<script>alert("view2");</script>: Fish & chips');
|
||||
$this->assertNoRaw('<script>alert("view2");</script>');
|
||||
$this->assertNoRaw('Fish & chips');
|
||||
|
||||
// Assert the Display label doesn't appear anywhere double escaped.
|
||||
$this->assertNoRaw('Fish & chips');
|
||||
$this->assertNoRaw('Fish &amp; chips');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,8 +143,8 @@ class BlockXssTest extends WebTestBase {
|
|||
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
// The block admin label is automatically XSS admin filtered.
|
||||
$this->assertRaw('alert("menu");');
|
||||
|
||||
$this->assertEscaped('<script>alert("menu");</script>');
|
||||
$this->assertNoRaw('<script>alert("menu");</script>');
|
||||
}
|
||||
|
||||
|
@ -116,8 +164,8 @@ class BlockXssTest extends WebTestBase {
|
|||
|
||||
$this->drupalGet(Url::fromRoute('block.admin_display'));
|
||||
$this->clickLinkPartialName('Place block');
|
||||
// The block admin label is automatically XSS admin filtered.
|
||||
$this->assertRaw('alert("block_content");');
|
||||
|
||||
$this->assertEscaped('<script>alert("block_content");</script>');
|
||||
$this->assertNoRaw('<script>alert("block_content");</script>');
|
||||
}
|
||||
|
||||
|
|
|
@ -11,57 +11,31 @@ use Drupal\block\Entity\Block;
|
|||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade block settings to block.block.*.yml.
|
||||
* Tests migration of blocks to configuration entities.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateBlockTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array(
|
||||
public static $modules = [
|
||||
'block',
|
||||
'views',
|
||||
'comment',
|
||||
'menu_ui',
|
||||
'block_content',
|
||||
'node',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['block_content']);
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
$entities = array(
|
||||
entity_create('menu', array('id' => 'primary-links')),
|
||||
entity_create('menu', array('id' => 'secondary-links')),
|
||||
entity_create('block_content', array('id' => 1, 'type' => 'basic', 'info' => $this->randomMachineName(8))),
|
||||
entity_create('block_content', array('id' => 2, 'type' => 'basic', 'info' => $this->randomMachineName(8))),
|
||||
);
|
||||
foreach ($entities as $entity) {
|
||||
$entity->enforceIsNew(TRUE);
|
||||
$entity->save();
|
||||
}
|
||||
$this->prepareMigrations(array(
|
||||
'd6_custom_block' => array(
|
||||
array(array(1), array(1)),
|
||||
array(array(2), array(2)),
|
||||
),
|
||||
'menu' => array(
|
||||
array(array('menu1'), array('menu')),
|
||||
),
|
||||
'd6_user_role' => array(
|
||||
array(array(2), array('authenticated')),
|
||||
array(array(3), array('migrate_test_role_1')),
|
||||
),
|
||||
));
|
||||
|
||||
// Set Bartik and Seven as the default public and admin theme.
|
||||
$config = $this->config('system.theme');
|
||||
$config->set('default', 'bartik');
|
||||
|
@ -69,114 +43,107 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
$config->save();
|
||||
|
||||
// Install one of D8's test themes.
|
||||
\Drupal::service('theme_handler')->install(array('test_theme'));
|
||||
\Drupal::service('theme_handler')->install(['test_theme']);
|
||||
|
||||
$this->executeMigration('d6_block');
|
||||
$this->executeMigrations([
|
||||
'd6_filter_format',
|
||||
'block_content_type',
|
||||
'block_content_body_field',
|
||||
'd6_custom_block',
|
||||
'menu',
|
||||
'd6_user_role',
|
||||
'd6_block',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the block settings migration.
|
||||
* Asserts various aspects of a block.
|
||||
*
|
||||
* @param string $id
|
||||
* The block ID.
|
||||
* @param string $module
|
||||
* The module.
|
||||
* @param array $visibility
|
||||
* The block visibility settings.
|
||||
* @param string $region
|
||||
* The display region.
|
||||
* @param string $theme
|
||||
* The theme.
|
||||
* @param string $weight
|
||||
* The block weight.
|
||||
*/
|
||||
public function assertEntity($id, $visibility, $region, $theme, $weight) {
|
||||
$block = Block::load($id);
|
||||
$this->assertTrue($block instanceof Block);
|
||||
$this->assertIdentical($visibility, $block->getVisibility());
|
||||
$this->assertIdentical($region, $block->getRegion());
|
||||
$this->assertIdentical($theme, $block->getTheme());
|
||||
$this->assertIdentical($weight, $block->getWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the block migration.
|
||||
*/
|
||||
public function testBlockMigration() {
|
||||
$blocks = Block::loadMultiple();
|
||||
$this->assertIdentical(count($blocks), 10);
|
||||
$this->assertIdentical(9, count($blocks));
|
||||
|
||||
// User blocks
|
||||
$test_block_user = $blocks['user'];
|
||||
$this->assertNotNull($test_block_user);
|
||||
$this->assertIdentical('sidebar_first', $test_block_user->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_user->getTheme());
|
||||
$visibility = $test_block_user->getVisibility();
|
||||
$this->assertTrue(empty($visibility));
|
||||
$this->assertIdentical(0, $test_block_user->getWeight());
|
||||
$visibility = [];
|
||||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = TRUE;
|
||||
$visibility['request_path']['pages'] = "<front>\n/node/1\n/blog/*";
|
||||
$this->assertEntity('user', $visibility, 'sidebar_first', 'bartik', 0);
|
||||
|
||||
$test_block_user_1 = $blocks['user_1'];
|
||||
$this->assertNotNull($test_block_user_1);
|
||||
$this->assertIdentical('sidebar_first', $test_block_user_1->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_user_1->getTheme());
|
||||
$visibility = $test_block_user_1->getVisibility();
|
||||
$this->assertTrue(empty($visibility));
|
||||
$this->assertIdentical(0, $test_block_user_1->getWeight());
|
||||
$visibility = [];
|
||||
$this->assertEntity('user_1', $visibility, 'sidebar_first', 'bartik', 0);
|
||||
|
||||
$test_block_user_2 = $blocks['user_2'];
|
||||
$this->assertNotNull($test_block_user_2);
|
||||
$this->assertIdentical('sidebar_second', $test_block_user_2->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_user_2->getTheme());
|
||||
$visibility = $test_block_user_2->getVisibility();
|
||||
$this->assertIdentical($visibility['user_role']['id'], 'user_role');
|
||||
$roles = array();
|
||||
$visibility['user_role']['id'] = 'user_role';
|
||||
$roles['authenticated'] = 'authenticated';
|
||||
$this->assertIdentical($visibility['user_role']['roles'], $roles);
|
||||
$this->assertFalse($visibility['user_role']['negate']);
|
||||
$this->assertIdentical(-9, $test_block_user_2->getWeight());
|
||||
$visibility['user_role']['roles'] = $roles;
|
||||
$context_mapping['user'] = '@user.current_user_context:current_user';
|
||||
$visibility['user_role']['context_mapping'] = $context_mapping;
|
||||
$visibility['user_role']['negate'] = FALSE;
|
||||
$this->assertEntity('user_2', $visibility, 'sidebar_second', 'bartik', -9);
|
||||
|
||||
$test_block_user_3 = $blocks['user_3'];
|
||||
$this->assertNotNull($test_block_user_3);
|
||||
$this->assertIdentical('sidebar_second', $test_block_user_3->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_user_3->getTheme());
|
||||
$visibility = $test_block_user_3->getVisibility();
|
||||
$this->assertIdentical($visibility['user_role']['id'], 'user_role');
|
||||
$roles = array();
|
||||
$roles['migrate_test_role_1'] = 'migrate_test_role_1';
|
||||
$this->assertIdentical($visibility['user_role']['roles'], $roles);
|
||||
$this->assertFalse($visibility['user_role']['negate']);
|
||||
$this->assertIdentical(-6, $test_block_user_3->getWeight());
|
||||
$visibility = [];
|
||||
$visibility['user_role']['id'] = 'user_role';
|
||||
$visibility['user_role']['roles'] = [
|
||||
'migrate_test_role_1' => 'migrate_test_role_1'
|
||||
];
|
||||
$context_mapping['user'] = '@user.current_user_context:current_user';
|
||||
$visibility['user_role']['context_mapping'] = $context_mapping;
|
||||
$visibility['user_role']['negate'] = FALSE;
|
||||
$this->assertEntity('user_3', $visibility, 'sidebar_second', 'bartik', -6);
|
||||
|
||||
// Check system block
|
||||
$test_block_system = $blocks['system'];
|
||||
$this->assertNotNull($test_block_system);
|
||||
$this->assertIdentical('footer', $test_block_system->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_system->getTheme());
|
||||
$visibility = $test_block_system->getVisibility();
|
||||
$this->assertIdentical('request_path', $visibility['request_path']['id']);
|
||||
$this->assertIdentical('node/1', $visibility['request_path']['pages']);
|
||||
$this->assertTrue($visibility['request_path']['negate']);
|
||||
$this->assertIdentical(-5, $test_block_system->getWeight());
|
||||
$visibility = [];
|
||||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = TRUE;
|
||||
$visibility['request_path']['pages'] = '/node/1';
|
||||
$this->assertEntity('system', $visibility, 'footer', 'bartik', -5);
|
||||
|
||||
// Check menu blocks
|
||||
$test_block_menu = $blocks['menu'];
|
||||
$this->assertNotNull($test_block_menu);
|
||||
$this->assertIdentical('header', $test_block_menu->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_menu->getTheme());
|
||||
$visibility = $test_block_menu->getVisibility();
|
||||
$this->assertTrue(empty($visibility));
|
||||
$this->assertIdentical(-5, $test_block_menu->getWeight());
|
||||
$visibility = [];
|
||||
$this->assertEntity('menu', $visibility, 'header', 'bartik', -5);
|
||||
|
||||
// Check custom blocks
|
||||
$test_block_block = $blocks['block'];
|
||||
$this->assertNotNull($test_block_block);
|
||||
$this->assertIdentical('content', $test_block_block->getRegion());
|
||||
$this->assertIdentical('bartik', $test_block_block->getTheme());
|
||||
$visibility = $test_block_block->getVisibility();
|
||||
$this->assertIdentical('request_path', $visibility['request_path']['id']);
|
||||
$this->assertIdentical('<front>', $visibility['request_path']['pages']);
|
||||
$this->assertFalse($visibility['request_path']['negate']);
|
||||
$this->assertIdentical(0, $test_block_block->getWeight());
|
||||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = FALSE;
|
||||
$visibility['request_path']['pages'] = '<front>';
|
||||
$this->assertEntity('block', $visibility, 'content', 'bartik', 0);
|
||||
|
||||
$test_block_block_1 = $blocks['block_1'];
|
||||
$this->assertNotNull($test_block_block_1);
|
||||
$this->assertIdentical('right', $test_block_block_1->getRegion());
|
||||
$this->assertIdentical('bluemarine', $test_block_block_1->getTheme());
|
||||
$visibility = $test_block_block_1->getVisibility();
|
||||
$this->assertIdentical('request_path', $visibility['request_path']['id']);
|
||||
$this->assertIdentical('node', $visibility['request_path']['pages']);
|
||||
$this->assertFalse($visibility['request_path']['negate']);
|
||||
$this->assertIdentical(-4, $test_block_block_1->getWeight());
|
||||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = FALSE;
|
||||
$visibility['request_path']['pages'] = '/node';
|
||||
$this->assertEntity('block_1', $visibility, 'sidebar_second', 'bluemarine', -4);
|
||||
|
||||
$test_block_block_2 = $blocks['block_2'];
|
||||
$this->assertNotNull($test_block_block_2);
|
||||
$this->assertIdentical('right', $test_block_block_2->getRegion());
|
||||
$this->assertIdentical('test_theme', $test_block_block_2->getTheme());
|
||||
$visibility = $test_block_block_2->getVisibility();
|
||||
$this->assertTrue(empty($visibility));
|
||||
$this->assertIdentical(-7, $test_block_block_2->getWeight());
|
||||
$visibility = [];
|
||||
$this->assertEntity('block_2', $visibility, 'right', 'test_theme', -7);
|
||||
|
||||
$test_block_block_3 = $blocks['block_3'];
|
||||
$this->assertNotNull($test_block_block_3);
|
||||
$this->assertIdentical('left', $test_block_block_3->getRegion());
|
||||
$this->assertIdentical('test_theme', $test_block_block_3->getTheme());
|
||||
$visibility = $test_block_block_3->getVisibility();
|
||||
$this->assertTrue(empty($visibility));
|
||||
$this->assertIdentical(-2, $test_block_block_3->getWeight());
|
||||
// Custom block with php code is not migrated.
|
||||
$block = Block::load('block_3');
|
||||
$this->assertFalse($block instanceof Block);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
162
core/modules/block/src/Tests/Migrate/d7/MigrateBlockTest.php
Normal file
162
core/modules/block/src/Tests/Migrate/d7/MigrateBlockTest.php
Normal file
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Tests\Migrate\d7\MigrateBlockTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of blocks to configuration entities.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class MigrateBlockTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = [
|
||||
'block',
|
||||
'views',
|
||||
'comment',
|
||||
'menu_ui',
|
||||
'block_content',
|
||||
'node',
|
||||
'text',
|
||||
'filter',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
// Set Bartik and Seven as the default public and admin theme.
|
||||
$config = $this->config('system.theme');
|
||||
$config->set('default', 'bartik');
|
||||
$config->set('admin', 'seven');
|
||||
$config->save();
|
||||
|
||||
// Install one of D8's test themes.
|
||||
\Drupal::service('theme_handler')->install(['bartik']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'd7_filter_format',
|
||||
'd7_user_role',
|
||||
'block_content_type',
|
||||
'block_content_body_field',
|
||||
'd7_custom_block',
|
||||
'd7_block',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a block.
|
||||
*
|
||||
* @param string $id
|
||||
* The block ID.
|
||||
* @param string $plugin_id
|
||||
* The block's plugin ID.
|
||||
* @param array $roles
|
||||
* Role IDs the block is expected to have.
|
||||
* @param string $pages
|
||||
* The list of pages on which the block should appear.
|
||||
* @param string $region
|
||||
* The display region.
|
||||
* @param string $theme
|
||||
* The theme.
|
||||
* @param string $weight
|
||||
* The block weight.
|
||||
*/
|
||||
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight) {
|
||||
$block = Block::load($id);
|
||||
$this->assertTrue($block instanceof Block);
|
||||
/** @var \Drupal\block\BlockInterface $block */
|
||||
$this->assertIdentical($plugin_id, $block->getPluginId());
|
||||
|
||||
$visibility = $block->getVisibility();
|
||||
if ($roles) {
|
||||
$this->assertIdentical($roles, array_values($visibility['user_role']['roles']));
|
||||
$this->assertIdentical('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
|
||||
}
|
||||
if ($pages) {
|
||||
$this->assertIdentical($pages, $visibility['request_path']['pages']);
|
||||
}
|
||||
|
||||
$this->assertIdentical($region, $block->getRegion());
|
||||
$this->assertIdentical($theme, $block->getTheme());
|
||||
$this->assertIdentical($weight, $block->getWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the block migration.
|
||||
*/
|
||||
public function testBlockMigration() {
|
||||
$this->assertEntity('bartik_system_main', 'system_main_block', [], '', 'content', 'bartik', 0);
|
||||
$this->assertEntity('bartik_search_form', 'search_form_block', [], '', 'sidebar_first', 'bartik', -1);
|
||||
$this->assertEntity('bartik_user_login', 'user_login_block', [], '', 'sidebar_first', 'bartik', 0);
|
||||
$this->assertEntity('bartik_system_powered-by', 'system_powered_by_block', [], '', 'footer', 'bartik', 10);
|
||||
$this->assertEntity('seven_system_main', 'system_main_block', [], '', 'content', 'seven', 0);
|
||||
$this->assertEntity('seven_user_login', 'user_login_block', [], '', 'content', 'seven', 10);
|
||||
|
||||
// The d7_custom_block migration should have migrated a block containing a
|
||||
// mildly amusing limerick. We'll need its UUID to determine
|
||||
// bartik_block_1's plugin ID.
|
||||
$uuid = BlockContent::load(1)->uuid();
|
||||
$this->assertEntity('bartik_block_1', 'block_content:' . $uuid, ['authenticated'], '', 'highlighted', 'bartik', 0);
|
||||
|
||||
// Assert that disabled blocks (or enabled blocks whose plugin IDs could
|
||||
// be resolved) did not migrate.
|
||||
$non_existent_blocks = [
|
||||
'bartik_system_navigation',
|
||||
'bartik_system_help',
|
||||
'seven_user_new',
|
||||
'seven_search_form',
|
||||
'bartik_comment_recent',
|
||||
'bartik_node_syndicate',
|
||||
'bartik_node_recent',
|
||||
'bartik_shortcut_shortcuts',
|
||||
'bartik_system_management',
|
||||
'bartik_system_user-menu',
|
||||
'bartik_system_main-menu',
|
||||
'bartik_user_new',
|
||||
'bartik_user_online',
|
||||
'seven_comment_recent',
|
||||
'seven_node_syndicate',
|
||||
'seven_shortcut_shortcuts',
|
||||
'seven_system_powered-by',
|
||||
'seven_system_navigation',
|
||||
'seven_system_management',
|
||||
'seven_system_user-menu',
|
||||
'seven_system_main-menu',
|
||||
'seven_user_online',
|
||||
'bartik_blog_recent',
|
||||
'bartik_book_navigation',
|
||||
'bartik_locale_language',
|
||||
'bartik_forum_active',
|
||||
'bartik_forum_new',
|
||||
'seven_blog_recent',
|
||||
'seven_book_navigation',
|
||||
'seven_locale_language',
|
||||
'seven_forum_active',
|
||||
'seven_forum_new',
|
||||
'bartik_menu_menu-test-menu',
|
||||
'bartik_statistics_popular',
|
||||
'seven_menu_menu-test-menu',
|
||||
'seven_statistics_popular',
|
||||
'seven_block_1',
|
||||
];
|
||||
$this->assertTrue(empty(Block::loadMultiple($non_existent_blocks)));
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\block\Tests\Views;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\views\Entity\View;
|
||||
use Drupal\views\Views;
|
||||
|
@ -271,6 +272,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
* Tests the various testcases of empty block rendering.
|
||||
*/
|
||||
public function testBlockEmptyRendering() {
|
||||
$url = new Url('test_page_test.test_page');
|
||||
// Remove all views_test_data entries.
|
||||
\Drupal::database()->truncate('views_test_data')->execute();
|
||||
/** @var \Drupal\views\ViewEntityInterface $view */
|
||||
|
@ -285,12 +287,12 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$display['display_options']['block_hide_empty'] = TRUE;
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->drupalGet($url);
|
||||
$this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
|
||||
// Ensure that the view cachability metadata is propagated even, for an
|
||||
// empty block.
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']);
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Add a header displayed on empty result.
|
||||
$display = &$view->getDisplay('block_1');
|
||||
|
@ -305,10 +307,10 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
];
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->drupalGet($url);
|
||||
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']);
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Hide the header on empty results.
|
||||
$display = &$view->getDisplay('block_1');
|
||||
|
@ -323,10 +325,10 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
];
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->drupalGet($url);
|
||||
$this->assertEqual(0, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']);
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Add an empty text.
|
||||
$display = &$view->getDisplay('block_1');
|
||||
|
@ -340,10 +342,10 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
];
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('');
|
||||
$this->drupalGet($url);
|
||||
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.path', 'url.query_args', 'user.roles:authenticated']);
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' ,'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue