Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -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.

View file

@ -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);
}
}

View file

@ -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;
}
}
}

View file

@ -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';
}
}

View file

@ -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 {

View file

@ -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');
}

View file

@ -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;
}
}

View file

@ -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';
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}