Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -17,11 +17,6 @@ function block_install() {
|
|||
Cache::invalidateTags(['rendered']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.0.0-beta
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Update block visibility context mapping.
|
||||
*/
|
||||
|
@ -122,7 +117,3 @@ function block_update_8003() {
|
|||
|
||||
return t('Block settings updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.0.0-beta".
|
||||
*/
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* Controls the visual building blocks a page is constructed with.
|
||||
*/
|
||||
|
||||
use Drupal\block\BlockInterface;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -19,24 +18,24 @@ use Drupal\block\Entity\Block;
|
|||
function block_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
case 'help.page.block':
|
||||
$block_content = \Drupal::moduleHandler()->moduleExists('block_content') ? \Drupal::url('help.page', array('name' => 'block_content')) : '#';
|
||||
$block_content = \Drupal::moduleHandler()->moduleExists('block_content') ? \Drupal::url('help.page', ['name' => 'block_content']) : '#';
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Block module allows you to place blocks in regions of your installed themes, and configure block settings. For more information, see the <a href=":blocks-documentation">online documentation for the Block module</a>.', array(':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block/')) . '</p>';
|
||||
$output .= '<p>' . t('The Block module allows you to place blocks in regions of your installed themes, and configure block settings. For more information, see the <a href=":blocks-documentation">online documentation for the Block module</a>.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block/']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Placing and moving blocks') . '</dt>';
|
||||
$output .= '<dd>' . t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', array(':blocks' => \Drupal::url('block.admin_display'))) . '</dd>';
|
||||
$output .= '<dd>' . t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', [':blocks' => \Drupal::url('block.admin_display')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Toggling between different themes') . '</dt>';
|
||||
$output .= '<dd>' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '</dd>';
|
||||
$output .= '<dt>' . t('Demonstrating block regions for a theme') . '</dt>';
|
||||
$output .= '<dd>' . t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', array(':blocks' => \Drupal::url('block.admin_display'))) . '</dd>';
|
||||
$output .= '<dd>' . t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', [':blocks' => \Drupal::url('block.admin_display')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Configuring block settings') . '</dt>';
|
||||
$output .= '<dd>' . t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', array(':blocks' => Drupal::url('block.admin_display'))) . '</dd>';
|
||||
$output .= '<dd>' . t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', [':blocks' => Drupal::url('block.admin_display')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Controlling visibility') . '</dt>';
|
||||
$output .= '<dd>' . t('You can control the visibility of a block by restricting it to specific pages, content types, and/or roles by setting the appropriate options under <em>Visibility settings</em> of the block configuration.') . '</dd>';
|
||||
$output .= '<dt>' . t('Adding custom blocks') . '</dt>';
|
||||
$output .= '<dd>' . t('You can add custom blocks, if the <em>Custom Block</em> module is installed. For more information, see the <a href=":blockcontent-help">Custom Block help page</a>.', array(':blockcontent-help' => $block_content)) . '</dd>';
|
||||
$output .= '<dd>' . t('You can add custom blocks, if the <em>Custom Block</em> module is installed. For more information, see the <a href=":blockcontent-help">Custom Block help page</a>.', [':blockcontent-help' => $block_content]) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
}
|
||||
|
@ -44,7 +43,7 @@ function block_help($route_name, RouteMatchInterface $route_match) {
|
|||
$demo_theme = $route_match->getParameter('theme') ?: \Drupal::config('system.theme')->get('default');
|
||||
$themes = \Drupal::service('theme_handler')->listInfo();
|
||||
$output = '<p>' . t('Block placement is specific to each theme on your site. Changes will not be saved until you click <em>Save blocks</em> at the bottom of the page.') . '</p>';
|
||||
$output .= '<p>' . \Drupal::l(t('Demonstrate block regions (@theme)', array('@theme' => $themes[$demo_theme]->info['name'])), new Url('block.admin_demo', array('theme' => $demo_theme))) . '</p>';
|
||||
$output .= '<p>' . \Drupal::l(t('Demonstrate block regions (@theme)', ['@theme' => $themes[$demo_theme]->info['name']]), new Url('block.admin_demo', ['theme' => $demo_theme])) . '</p>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +52,11 @@ function block_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function block_theme() {
|
||||
return array(
|
||||
'block' => array(
|
||||
return [
|
||||
'block' => [
|
||||
'render element' => 'elements',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,12 +65,12 @@ function block_theme() {
|
|||
function block_page_top(array &$page_top) {
|
||||
if (\Drupal::routeMatch()->getRouteName() === 'block.admin_demo') {
|
||||
$theme = \Drupal::theme()->getActiveTheme()->getName();
|
||||
$page_top['backlink'] = array(
|
||||
$page_top['backlink'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Exit block region demonstration'),
|
||||
'#options' => array('attributes' => array('class' => array('block-demo-backlink'))),
|
||||
'#options' => ['attributes' => ['class' => ['block-demo-backlink']]],
|
||||
'#weight' => -10,
|
||||
);
|
||||
];
|
||||
if (\Drupal::config('system.theme')->get('default') == $theme) {
|
||||
$page_top['backlink']['#url'] = Url::fromRoute('block.admin_display');
|
||||
}
|
||||
|
@ -109,12 +108,12 @@ function block_themes_installed($theme_list) {
|
|||
*/
|
||||
function block_theme_initialize($theme) {
|
||||
// Initialize theme's blocks if none already registered.
|
||||
$has_blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(array('theme' => $theme));
|
||||
$has_blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['theme' => $theme]);
|
||||
if (!$has_blocks) {
|
||||
$default_theme = \Drupal::config('system.theme')->get('default');
|
||||
// Apply only to new theme's visible regions.
|
||||
$regions = system_region_list($theme, REGIONS_VISIBLE);
|
||||
$default_theme_blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(array('theme' => $default_theme));
|
||||
$default_theme_blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['theme' => $default_theme]);
|
||||
foreach ($default_theme_blocks as $default_theme_block_id => $default_theme_block) {
|
||||
if (strpos($default_theme_block_id, $default_theme . '_') === 0) {
|
||||
$id = str_replace($default_theme, $theme, $default_theme_block_id);
|
||||
|
@ -144,17 +143,14 @@ function block_rebuild() {
|
|||
$blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['theme' => $theme]);
|
||||
foreach ($blocks as $block_id => $block) {
|
||||
// Disable blocks in invalid regions.
|
||||
$region = $block->getRegion();
|
||||
if ($region !== BlockInterface::BLOCK_REGION_NONE) {
|
||||
if (!empty($region) && !isset($regions[$region]) && $block->status()) {
|
||||
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $region]), 'warning');
|
||||
$block->disable();
|
||||
}
|
||||
// Set region to none if not enabled.
|
||||
if (!$block->status()) {
|
||||
$block->setRegion(BlockInterface::BLOCK_REGION_NONE);
|
||||
$block->save();
|
||||
if (!isset($regions[$block->getRegion()])) {
|
||||
if ($block->status()) {
|
||||
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()]), 'warning');
|
||||
}
|
||||
$block
|
||||
->setRegion(system_default_region($theme))
|
||||
->disable()
|
||||
->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +161,7 @@ function block_rebuild() {
|
|||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function block_theme_suggestions_block(array $variables) {
|
||||
$suggestions = array();
|
||||
$suggestions = [];
|
||||
|
||||
$suggestions[] = 'block__' . $variables['elements']['#configuration']['provider'];
|
||||
// Hyphens (-) and underscores (_) play a special role in theme suggestions.
|
||||
|
|
|
@ -5,11 +5,6 @@
|
|||
* Post update functions for Block.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.0.0-beta
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Disable all blocks with missing context IDs in block_update_8001().
|
||||
*/
|
||||
|
@ -63,10 +58,10 @@ function block_post_update_disable_blocks_with_missing_contexts() {
|
|||
$message = t('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:');
|
||||
$message .= '<ul>';
|
||||
foreach ($blocks as $disabled_block_id => $disabled_block) {
|
||||
$message .= '<li>' . t('@label (Visibility: @plugin_ids)', array(
|
||||
$message .= '<li>' . t('@label (Visibility: @plugin_ids)', [
|
||||
'@label' => $disabled_block->get('settings')['label'],
|
||||
'@plugin_ids' => implode(', ', array_intersect_key($condition_plugin_id_label_map, array_flip(array_keys($block_update_8001[$disabled_block_id]['missing_context_ids']))))
|
||||
)) . '</li>';
|
||||
]) . '</li>';
|
||||
}
|
||||
$message .= '</ul>';
|
||||
|
||||
|
@ -75,13 +70,11 @@ function block_post_update_disable_blocks_with_missing_contexts() {
|
|||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.0.0-beta".
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.2.x
|
||||
* @{
|
||||
* Disable blocks that are placed into the "disabled" region.
|
||||
*/
|
||||
function block_post_update_disabled_region_update() {
|
||||
// An empty update will flush caches, forcing block_rebuild() to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix invalid 'negate' values in block visibility conditions.
|
||||
|
@ -106,7 +99,3 @@ function block_post_update_fix_negate_in_conditions() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.2.x".
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,24 @@ entity.block.edit_form:
|
|||
requirements:
|
||||
_entity_access: 'block.update'
|
||||
|
||||
entity.block.enable:
|
||||
path: '/admin/structure/block/manage/{block}/enable'
|
||||
defaults:
|
||||
_controller: '\Drupal\block\Controller\BlockController::performOperation'
|
||||
op: enable
|
||||
requirements:
|
||||
_entity_access: 'block.enable'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
entity.block.disable:
|
||||
path: '/admin/structure/block/manage/{block}/disable'
|
||||
defaults:
|
||||
_controller: '\Drupal\block\Controller\BlockController::performOperation'
|
||||
op: disable
|
||||
requirements:
|
||||
_entity_access: 'block.disable'
|
||||
_csrf_token: 'TRUE'
|
||||
|
||||
block.admin_display:
|
||||
path: '/admin/structure/block'
|
||||
defaults:
|
||||
|
|
|
@ -40,3 +40,7 @@ a.block-demo-backlink:hover {
|
|||
.block-form .form-item-settings-admin-label label:after {
|
||||
content: ':';
|
||||
}
|
||||
.block-disabled:not(:hover) {
|
||||
background: #fcfcfa;
|
||||
opacity: 0.675;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ use Drupal\Core\Entity\EntityAccessControlHandler;
|
|||
use Drupal\Core\Entity\EntityHandlerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Executable\ExecutableManagerInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
|
||||
use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginInterface;
|
||||
|
@ -27,13 +26,6 @@ class BlockAccessControlHandler extends EntityAccessControlHandler implements En
|
|||
|
||||
use ConditionAccessResolverTrait;
|
||||
|
||||
/**
|
||||
* The condition plugin manager.
|
||||
*
|
||||
* @var \Drupal\Core\Executable\ExecutableManagerInterface
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The plugin context handler.
|
||||
*
|
||||
|
@ -54,7 +46,6 @@ class BlockAccessControlHandler extends EntityAccessControlHandler implements En
|
|||
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
||||
return new static(
|
||||
$entity_type,
|
||||
$container->get('plugin.manager.condition'),
|
||||
$container->get('context.handler'),
|
||||
$container->get('context.repository')
|
||||
);
|
||||
|
@ -65,16 +56,13 @@ class BlockAccessControlHandler extends EntityAccessControlHandler implements En
|
|||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
* @param \Drupal\Core\Executable\ExecutableManagerInterface $manager
|
||||
* The ConditionManager for checking visibility of blocks.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
|
||||
* The ContextHandler for applying contexts to conditions properly.
|
||||
* @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface $context_repository
|
||||
* The lazy context repository service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ExecutableManagerInterface $manager, ContextHandlerInterface $context_handler, ContextRepositoryInterface $context_repository ) {
|
||||
public function __construct(EntityTypeInterface $entity_type, ContextHandlerInterface $context_handler, ContextRepositoryInterface $context_repository ) {
|
||||
parent::__construct($entity_type);
|
||||
$this->manager = $manager;
|
||||
$this->contextHandler = $context_handler;
|
||||
$this->contextRepository = $context_repository;
|
||||
}
|
||||
|
|
|
@ -140,66 +140,66 @@ class BlockForm extends EntityForm {
|
|||
$form['visibility'] = $this->buildVisibilityInterface([], $form_state);
|
||||
|
||||
// If creating a new block, calculate a safe default machine name.
|
||||
$form['id'] = array(
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#maxlength' => 64,
|
||||
'#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'),
|
||||
'#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity),
|
||||
'#machine_name' => array(
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\block\Entity\Block::load',
|
||||
'replace_pattern' => '[^a-z0-9_.]+',
|
||||
'source' => array('settings', 'label'),
|
||||
),
|
||||
'source' => ['settings', 'label'],
|
||||
],
|
||||
'#required' => TRUE,
|
||||
'#disabled' => !$entity->isNew(),
|
||||
);
|
||||
];
|
||||
|
||||
// Theme settings.
|
||||
if ($entity->getTheme()) {
|
||||
$form['theme'] = array(
|
||||
$form['theme'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $theme,
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$theme_options = array();
|
||||
$theme_options = [];
|
||||
foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) {
|
||||
if (!empty($theme_info->status)) {
|
||||
$theme_options[$theme_name] = $theme_info->info['name'];
|
||||
}
|
||||
}
|
||||
$form['theme'] = array(
|
||||
$form['theme'] = [
|
||||
'#type' => 'select',
|
||||
'#options' => $theme_options,
|
||||
'#title' => t('Theme'),
|
||||
'#default_value' => $theme,
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => '::themeSwitch',
|
||||
'wrapper' => 'edit-block-region-wrapper',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Hidden weight setting.
|
||||
$weight = $entity->isNew() ? $this->getRequest()->query->get('weight', 0) : $entity->getWeight();
|
||||
$form['weight'] = array(
|
||||
$form['weight'] = [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $weight,
|
||||
);
|
||||
];
|
||||
|
||||
// Region settings.
|
||||
$entity_region = $entity->getRegion();
|
||||
$region = $entity->isNew() ? $this->getRequest()->query->get('region', $entity_region) : $entity_region;
|
||||
$form['region'] = array(
|
||||
$form['region'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Region'),
|
||||
'#description' => $this->t('Select the region where this block should be displayed.'),
|
||||
'#default_value' => $region,
|
||||
'#empty_value' => BlockInterface::BLOCK_REGION_NONE,
|
||||
'#required' => TRUE,
|
||||
'#options' => system_region_list($theme, REGIONS_VISIBLE),
|
||||
'#prefix' => '<div id="edit-block-region-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
$form['#attached']['library'][] = 'block/drupal.block.admin';
|
||||
return $form;
|
||||
}
|
||||
|
@ -292,6 +292,7 @@ class BlockForm extends EntityForm {
|
|||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
$actions = parent::actions($form, $form_state);
|
||||
$actions['submit']['#value'] = $this->t('Save block');
|
||||
$actions['delete']['#title'] = $this->t('Remove block');
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
@ -359,10 +360,10 @@ class BlockForm extends EntityForm {
|
|||
drupal_set_message($this->t('The block configuration has been saved.'));
|
||||
$form_state->setRedirect(
|
||||
'block.admin_display_theme',
|
||||
array(
|
||||
[
|
||||
'theme' => $form_state->getValue('theme'),
|
||||
),
|
||||
array('query' => array('block-placement' => Html::getClass($this->entity->id())))
|
||||
],
|
||||
['query' => ['block-placement' => Html::getClass($this->entity->id())]]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\block;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
|
@ -11,11 +12,16 @@ interface BlockInterface extends ConfigEntityInterface {
|
|||
|
||||
/**
|
||||
* Indicates the block label (title) should be displayed to end users.
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Block\BlockPluginInterface::BLOCK_LABEL_VISIBLE.
|
||||
*/
|
||||
const BLOCK_LABEL_VISIBLE = 'visible';
|
||||
const BLOCK_LABEL_VISIBLE = BlockPluginInterface::BLOCK_LABEL_VISIBLE;
|
||||
|
||||
/**
|
||||
* Denotes that a block is not enabled in any region and should not be shown.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
*/
|
||||
const BLOCK_REGION_NONE = -1;
|
||||
|
||||
|
|
|
@ -125,15 +125,15 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
// Build the form tree.
|
||||
$form['blocks'] = $this->buildBlocksForm();
|
||||
|
||||
$form['actions'] = array(
|
||||
$form['actions'] = [
|
||||
'#tree' => FALSE,
|
||||
'#type' => 'actions',
|
||||
);
|
||||
$form['actions']['submit'] = array(
|
||||
];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save blocks'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -150,28 +150,29 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
/** @var \Drupal\block\BlockInterface[] $entities */
|
||||
foreach ($entities as $entity_id => $entity) {
|
||||
$definition = $entity->getPlugin()->getPluginDefinition();
|
||||
$blocks[$entity->getRegion()][$entity_id] = array(
|
||||
$blocks[$entity->getRegion()][$entity_id] = [
|
||||
'label' => $entity->label(),
|
||||
'entity_id' => $entity_id,
|
||||
'weight' => $entity->getWeight(),
|
||||
'entity' => $entity,
|
||||
'category' => $definition['category'],
|
||||
);
|
||||
'status' => $entity->status(),
|
||||
];
|
||||
}
|
||||
|
||||
$form = array(
|
||||
$form = [
|
||||
'#type' => 'table',
|
||||
'#header' => array(
|
||||
'#header' => [
|
||||
$this->t('Block'),
|
||||
$this->t('Category'),
|
||||
$this->t('Region'),
|
||||
$this->t('Weight'),
|
||||
$this->t('Operations'),
|
||||
),
|
||||
'#attributes' => array(
|
||||
],
|
||||
'#attributes' => [
|
||||
'id' => 'blocks',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Weights range from -delta to +delta, so delta should be at least half
|
||||
// of the amount of blocks present. This makes sure all blocks in the same
|
||||
|
@ -186,41 +187,40 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
|
||||
// Loop over each region and build blocks.
|
||||
$regions = $this->systemRegionList($this->getThemeName(), REGIONS_VISIBLE);
|
||||
$block_regions_with_disabled = $regions + array(BlockInterface::BLOCK_REGION_NONE => $this->t('Disabled', array(), array('context' => 'Plural')));
|
||||
foreach ($block_regions_with_disabled as $region => $title) {
|
||||
$form['#tabledrag'][] = array(
|
||||
foreach ($regions as $region => $title) {
|
||||
$form['#tabledrag'][] = [
|
||||
'action' => 'match',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'block-region-select',
|
||||
'subgroup' => 'block-region-' . $region,
|
||||
'hidden' => FALSE,
|
||||
);
|
||||
$form['#tabledrag'][] = array(
|
||||
];
|
||||
$form['#tabledrag'][] = [
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'block-weight',
|
||||
'subgroup' => 'block-weight-' . $region,
|
||||
);
|
||||
];
|
||||
|
||||
$form['region-' . $region] = array(
|
||||
'#attributes' => array(
|
||||
'class' => array('region-title', 'region-title-' . $region),
|
||||
$form['region-' . $region] = [
|
||||
'#attributes' => [
|
||||
'class' => ['region-title', 'region-title-' . $region],
|
||||
'no_striping' => TRUE,
|
||||
),
|
||||
);
|
||||
$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],
|
||||
],
|
||||
];
|
||||
$form['region-' . $region]['title'] = [
|
||||
'#theme_wrappers' => [
|
||||
'container' => [
|
||||
'#attributes' => ['class' => 'region-title__action'],
|
||||
]
|
||||
],
|
||||
'#prefix' => $title,
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Place block <span class="visually-hidden">in the %region region</span>', ['%region' => $block_regions_with_disabled[$region]]),
|
||||
'#title' => $this->t('Place block <span class="visually-hidden">in the %region region</span>', ['%region' => $title]),
|
||||
'#url' => Url::fromRoute('block.admin_library', ['theme' => $this->getThemeName()], ['query' => ['region' => $region]]),
|
||||
'#wrapper_attributes' => array(
|
||||
'#wrapper_attributes' => [
|
||||
'colspan' => 5,
|
||||
),
|
||||
],
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax', 'button', 'button--small'],
|
||||
'data-dialog-type' => 'modal',
|
||||
|
@ -228,73 +228,74 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
'width' => 700,
|
||||
]),
|
||||
],
|
||||
);
|
||||
];
|
||||
|
||||
$form['region-' . $region . '-message'] = array(
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
$form['region-' . $region . '-message'] = [
|
||||
'#attributes' => [
|
||||
'class' => [
|
||||
'region-message',
|
||||
'region-' . $region . '-message',
|
||||
empty($blocks[$region]) ? 'region-empty' : 'region-populated',
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['region-' . $region . '-message']['message'] = array(
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['region-' . $region . '-message']['message'] = [
|
||||
'#markup' => '<em>' . $this->t('No blocks in this region') . '</em>',
|
||||
'#wrapper_attributes' => array(
|
||||
'#wrapper_attributes' => [
|
||||
'colspan' => 5,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
if (isset($blocks[$region])) {
|
||||
foreach ($blocks[$region] as $info) {
|
||||
$entity_id = $info['entity_id'];
|
||||
|
||||
$form[$entity_id] = array(
|
||||
'#attributes' => array(
|
||||
'class' => array('draggable'),
|
||||
),
|
||||
);
|
||||
$form[$entity_id] = [
|
||||
'#attributes' => [
|
||||
'class' => ['draggable'],
|
||||
],
|
||||
];
|
||||
$form[$entity_id]['#attributes']['class'][] = $info['status'] ? 'block-enabled' : 'block-disabled';
|
||||
if ($placement && $placement == Html::getClass($entity_id)) {
|
||||
$form[$entity_id]['#attributes']['class'][] = 'color-success';
|
||||
$form[$entity_id]['#attributes']['class'][] = 'js-block-placed';
|
||||
}
|
||||
$form[$entity_id]['info'] = array(
|
||||
'#plain_text' => $info['label'],
|
||||
'#wrapper_attributes' => array(
|
||||
'class' => array('block'),
|
||||
),
|
||||
);
|
||||
$form[$entity_id]['type'] = array(
|
||||
$form[$entity_id]['info'] = [
|
||||
'#plain_text' => $info['status'] ? $info['label'] : $this->t('@label (disabled)', ['@label' => $info['label']]),
|
||||
'#wrapper_attributes' => [
|
||||
'class' => ['block'],
|
||||
],
|
||||
];
|
||||
$form[$entity_id]['type'] = [
|
||||
'#markup' => $info['category'],
|
||||
);
|
||||
$form[$entity_id]['region-theme']['region'] = array(
|
||||
];
|
||||
$form[$entity_id]['region-theme']['region'] = [
|
||||
'#type' => 'select',
|
||||
'#default_value' => $region,
|
||||
'#empty_value' => BlockInterface::BLOCK_REGION_NONE,
|
||||
'#title' => $this->t('Region for @block block', array('@block' => $info['label'])),
|
||||
'#required' => TRUE,
|
||||
'#title' => $this->t('Region for @block block', ['@block' => $info['label']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $regions,
|
||||
'#attributes' => array(
|
||||
'class' => array('block-region-select', 'block-region-' . $region),
|
||||
),
|
||||
'#parents' => array('blocks', $entity_id, 'region'),
|
||||
);
|
||||
$form[$entity_id]['region-theme']['theme'] = array(
|
||||
'#attributes' => [
|
||||
'class' => ['block-region-select', 'block-region-' . $region],
|
||||
],
|
||||
'#parents' => ['blocks', $entity_id, 'region'],
|
||||
];
|
||||
$form[$entity_id]['region-theme']['theme'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $this->getThemeName(),
|
||||
'#parents' => array('blocks', $entity_id, 'theme'),
|
||||
);
|
||||
$form[$entity_id]['weight'] = array(
|
||||
'#parents' => ['blocks', $entity_id, 'theme'],
|
||||
];
|
||||
$form[$entity_id]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#default_value' => $info['weight'],
|
||||
'#delta' => $weight_delta,
|
||||
'#title' => $this->t('Weight for @block block', array('@block' => $info['label'])),
|
||||
'#title' => $this->t('Weight for @block block', ['@block' => $info['label']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#attributes' => array(
|
||||
'class' => array('block-weight', 'block-weight-' . $region),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['block-weight', 'block-weight-' . $region],
|
||||
],
|
||||
];
|
||||
$form[$entity_id]['operations'] = $this->buildOperations($info['entity']);
|
||||
}
|
||||
}
|
||||
|
@ -341,6 +342,9 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
$operations['edit']['title'] = $this->t('Configure');
|
||||
}
|
||||
|
||||
if (isset($operations['delete'])) {
|
||||
$operations['delete']['title'] = $this->t('Remove');
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
|
||||
|
@ -358,15 +362,9 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
|
|||
$entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks')));
|
||||
/** @var \Drupal\block\BlockInterface[] $entities */
|
||||
foreach ($entities as $entity_id => $entity) {
|
||||
$entity_values = $form_state->getValue(array('blocks', $entity_id));
|
||||
$entity_values = $form_state->getValue(['blocks', $entity_id]);
|
||||
$entity->setWeight($entity_values['weight']);
|
||||
$entity->setRegion($entity_values['region']);
|
||||
if ($entity->getRegion() == BlockInterface::BLOCK_REGION_NONE) {
|
||||
$entity->disable();
|
||||
}
|
||||
else {
|
||||
$entity->enable();
|
||||
}
|
||||
$entity->save();
|
||||
}
|
||||
drupal_set_message(t('The block settings have been updated.'));
|
||||
|
|
|
@ -48,10 +48,10 @@ class BlockRepository implements BlockRepositoryInterface {
|
|||
public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) {
|
||||
$active_theme = $this->themeManager->getActiveTheme();
|
||||
// Build an array of the region names in the right order.
|
||||
$empty = array_fill_keys($active_theme->getRegions(), array());
|
||||
$empty = array_fill_keys($active_theme->getRegions(), []);
|
||||
|
||||
$full = array();
|
||||
foreach ($this->blockStorage->loadByProperties(array('theme' => $active_theme->getName())) as $block_id => $block) {
|
||||
$full = [];
|
||||
foreach ($this->blockStorage->loadByProperties(['theme' => $active_theme->getName()]) as $block_id => $block) {
|
||||
/** @var \Drupal\block\BlockInterface $block */
|
||||
$access = $block->access('view', NULL, TRUE);
|
||||
$region = $block->getRegion();
|
||||
|
|
|
@ -4,6 +4,20 @@ namespace Drupal\block;
|
|||
|
||||
interface BlockRepositoryInterface {
|
||||
|
||||
/**
|
||||
* Return only visible regions.
|
||||
*
|
||||
* @see system_region_list()
|
||||
*/
|
||||
const REGIONS_VISIBLE = 'visible';
|
||||
|
||||
/**
|
||||
* Return all regions.
|
||||
*
|
||||
* @see system_region_list()
|
||||
*/
|
||||
const REGIONS_ALL = 'all';
|
||||
|
||||
/**
|
||||
* Returns an array of regions and their block entities.
|
||||
*
|
||||
|
|
|
@ -68,16 +68,16 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
|
||||
$build = $this->viewMultiple(array($entity), $view_mode, $langcode);
|
||||
$build = $this->viewMultiple([$entity], $view_mode, $langcode);
|
||||
return reset($build);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
|
||||
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
|
||||
/** @var \Drupal\block\BlockInterface[] $entities */
|
||||
$build = array();
|
||||
$build = [];
|
||||
foreach ($entities as $entity) {
|
||||
$entity_id = $entity->id();
|
||||
$plugin = $entity->getPlugin();
|
||||
|
@ -87,7 +87,7 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
|
||||
// Create the render array for the block as a whole.
|
||||
// @see template_preprocess_block().
|
||||
$build[$entity_id] = array(
|
||||
$build[$entity_id] = [
|
||||
'#cache' => [
|
||||
'keys' => ['entity_view', 'block', $entity->id()],
|
||||
'contexts' => Cache::mergeContexts(
|
||||
|
@ -98,7 +98,7 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
'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);
|
||||
|
@ -216,7 +216,7 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
// #contextual_links is information about the *entire* block. Therefore,
|
||||
// we must move these properties from $content and merge them into the
|
||||
// top-level element.
|
||||
foreach (array('#attributes', '#contextual_links') as $property) {
|
||||
foreach (['#attributes', '#contextual_links'] as $property) {
|
||||
if (isset($content[$property])) {
|
||||
$build[$property] += $content[$property];
|
||||
unset($content[$property]);
|
||||
|
@ -231,10 +231,10 @@ class BlockViewBuilder extends EntityViewBuilder {
|
|||
// render cached, so we can avoid the work of having to repeatedly
|
||||
// determine whether the block is empty. For instance, modifying or adding
|
||||
// entities could cause the block to no longer be empty.
|
||||
$build = array(
|
||||
$build = [
|
||||
'#markup' => '',
|
||||
'#cache' => $build['#cache'],
|
||||
);
|
||||
];
|
||||
// If $content is not empty, then it contains cacheability metadata, and
|
||||
// we must merge it with the existing cacheability metadata. This allows
|
||||
// blocks to be empty, yet still bubble cacheability metadata, to indicate
|
||||
|
|
|
@ -22,7 +22,7 @@ class BlockAddController extends ControllerBase {
|
|||
*/
|
||||
public function blockAddConfigureForm($plugin_id, $theme) {
|
||||
// Create a block entity.
|
||||
$entity = $this->entityManager()->getStorage('block')->create(array('plugin' => $plugin_id, 'theme' => $theme));
|
||||
$entity = $this->entityManager()->getStorage('block')->create(['plugin' => $plugin_id, 'theme' => $theme]);
|
||||
|
||||
return $this->entityFormBuilder()->getForm($entity);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\block\BlockInterface;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -39,6 +40,23 @@ class BlockController extends ControllerBase {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a method on a block and reloads the listing page.
|
||||
*
|
||||
* @param \Drupal\block\BlockInterface $block
|
||||
* The block being acted upon.
|
||||
* @param string $op
|
||||
* The operation to perform, e.g., 'enable' or 'disable'.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* A redirect back to the listing page.
|
||||
*/
|
||||
public function performOperation(BlockInterface $block, $op) {
|
||||
$block->$op()->save();
|
||||
drupal_set_message($this->t('The block settings have been updated.'));
|
||||
return $this->redirect('block.admin_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block theme demo page.
|
||||
*
|
||||
|
@ -56,7 +74,7 @@ class BlockController extends ControllerBase {
|
|||
$page = [
|
||||
'#title' => Html::escape($this->themeHandler->getName($theme)),
|
||||
'#type' => 'page',
|
||||
'#attached' => array(
|
||||
'#attached' => [
|
||||
'drupalSettings' => [
|
||||
// The block demonstration page is not marked as an administrative
|
||||
// page by \Drupal::service('router.admin_context')->isAdminRoute()
|
||||
|
@ -65,20 +83,20 @@ class BlockController extends ControllerBase {
|
|||
// is an actual administrative page.
|
||||
'path' => ['currentPathIsAdmin' => TRUE],
|
||||
],
|
||||
'library' => array(
|
||||
'library' => [
|
||||
'block/drupal.block.admin',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Show descriptions in each visible page region, nothing else.
|
||||
$visible_regions = $this->getVisibleRegionNames($theme);
|
||||
foreach (array_keys($visible_regions) as $region) {
|
||||
$page[$region]['block_description'] = array(
|
||||
$page[$region]['block_description'] = [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<div class="block-region demo-block">{{ region_name }}</div>',
|
||||
'#context' => array('region_name' => $visible_regions[$region]),
|
||||
);
|
||||
'#context' => ['region_name' => $visible_regions[$region]],
|
||||
];
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
|
|
@ -51,10 +51,10 @@ class CategoryAutocompleteController implements ContainerInjectionInterface {
|
|||
*/
|
||||
public function autocomplete(Request $request) {
|
||||
$typed_category = $request->query->get('q');
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
foreach ($this->blockManager->getCategories() as $category) {
|
||||
if (stripos($category, $typed_category) === 0) {
|
||||
$matches[] = array('value' => $category, 'label' => Html::escape($category));
|
||||
$matches[] = ['value' => $category, 'label' => Html::escape($category)];
|
||||
}
|
||||
}
|
||||
return new JsonResponse($matches);
|
||||
|
|
|
@ -28,11 +28,14 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
* },
|
||||
* admin_permission = "administer blocks",
|
||||
* entity_keys = {
|
||||
* "id" = "id"
|
||||
* "id" = "id",
|
||||
* "status" = "status"
|
||||
* },
|
||||
* links = {
|
||||
* "delete-form" = "/admin/structure/block/manage/{block}/delete",
|
||||
* "edit-form" = "/admin/structure/block/manage/{block}"
|
||||
* "edit-form" = "/admin/structure/block/manage/{block}",
|
||||
* "enable" = "/admin/structure/block/manage/{block}/enable",
|
||||
* "disable" = "/admin/structure/block/manage/{block}/disable",
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
|
@ -63,14 +66,14 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = array();
|
||||
protected $settings = [];
|
||||
|
||||
/**
|
||||
* The region this block is placed in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $region = self::BLOCK_REGION_NONE;
|
||||
protected $region;
|
||||
|
||||
/**
|
||||
* The block weight.
|
||||
|
@ -209,13 +212,13 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
|||
if ($status !== 0) {
|
||||
return $status;
|
||||
}
|
||||
// Sort by weight, unless disabled.
|
||||
if ($a->getRegion() != static::BLOCK_REGION_NONE) {
|
||||
$weight = $a->getWeight() - $b->getWeight();
|
||||
if ($weight) {
|
||||
return $weight;
|
||||
}
|
||||
|
||||
// Sort by weight.
|
||||
$weight = $a->getWeight() - $b->getWeight();
|
||||
if ($weight) {
|
||||
return $weight;
|
||||
}
|
||||
|
||||
// Sort by label.
|
||||
return strcmp($a->label(), $b->label());
|
||||
}
|
||||
|
@ -327,4 +330,21 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
|
|||
return $duplicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preSave(EntityStorageInterface $storage) {
|
||||
parent::preSave($storage);
|
||||
|
||||
// Ensure the region is valid to mirror the behavior of block_rebuild().
|
||||
// This is done primarily for backwards compatibility support of
|
||||
// \Drupal\block\BlockInterface::BLOCK_REGION_NONE.
|
||||
$regions = system_region_list($this->theme);
|
||||
if (!isset($regions[$this->region]) && $this->status()) {
|
||||
$this
|
||||
->setRegion(system_default_region($this->theme))
|
||||
->disable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ class BlockPageDisplayVariantSubscriber implements EventSubscriberInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = array('onSelectPageDisplayVariant');
|
||||
public static function getSubscribedEvents() {
|
||||
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = ['onSelectPageDisplayVariant'];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,4 +17,32 @@ class BlockDeleteForm extends EntityDeleteForm {
|
|||
return new Url('block.admin_display');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to remove the @entity-type %label?', [
|
||||
'@entity-type' => $this->getEntity()->getEntityType()->getLowercaseLabel(),
|
||||
'%label' => $this->getEntity()->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDeletionMessage() {
|
||||
$entity = $this->getEntity();
|
||||
return $this->t('The @entity-type %label has been removed.', [
|
||||
'@entity-type' => $entity->getEntityType()->getLowercaseLabel(),
|
||||
'%label' => $entity->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class ThemeLocalTask extends DeriverBase implements ContainerDeriverInterface {
|
|||
if ($this->themeHandler->hasUi($theme_name)) {
|
||||
$this->derivatives[$theme_name] = $base_plugin_definition;
|
||||
$this->derivatives[$theme_name]['title'] = $theme->info['name'];
|
||||
$this->derivatives[$theme_name]['route_parameters'] = array('theme' => $theme_name);
|
||||
$this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
|
||||
}
|
||||
// Default task!
|
||||
if ($default_theme == $theme_name) {
|
||||
|
|
|
@ -17,10 +17,10 @@ class EntityBlock extends EntityConfigBase {
|
|||
*/
|
||||
protected function getEntityId(Row $row) {
|
||||
// Try to find the block by its plugin ID and theme.
|
||||
$properties = array(
|
||||
$properties = [
|
||||
'plugin' => $row->getDestinationProperty('plugin'),
|
||||
'theme' => $row->getDestinationProperty('theme'),
|
||||
);
|
||||
];
|
||||
$blocks = array_keys($this->storage->loadByProperties($properties));
|
||||
return reset($blocks);
|
||||
}
|
||||
|
|
|
@ -47,12 +47,12 @@ 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(
|
||||
$migration_configuration = [
|
||||
'migration' => [
|
||||
'd6_custom_block',
|
||||
'd7_custom_block',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
|
|
|
@ -43,7 +43,7 @@ class BlockRegion extends StaticMap implements ContainerFactoryPluginInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
$regions = array();
|
||||
$regions = [];
|
||||
foreach ($container->get('theme_handler')->listInfo() as $key => $theme) {
|
||||
$regions[$key] = $theme->info['regions'];
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\block\Plugin\migrate\process;
|
||||
|
||||
use Drupal\block\BlockInterface;
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
@ -21,10 +21,10 @@ class BlockSettings extends ProcessPluginBase {
|
|||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($plugin, $delta, $old_settings, $title) = $value;
|
||||
$settings = array();
|
||||
$settings = [];
|
||||
$settings['label'] = $title;
|
||||
if ($title) {
|
||||
$settings['label_display'] = BlockInterface::BLOCK_LABEL_VISIBLE;
|
||||
$settings['label_display'] = BlockPluginInterface::BLOCK_LABEL_VISIBLE;
|
||||
}
|
||||
else {
|
||||
$settings['label_display'] = '0';
|
||||
|
|
|
@ -59,12 +59,12 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
$migration_configuration = array(
|
||||
'migration' => array(
|
||||
$migration_configuration = [
|
||||
'migration' => [
|
||||
'd6_user_role',
|
||||
'd7_user_role',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
|
@ -80,18 +80,18 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
|
|||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($old_visibility, $pages, $roles) = $value;
|
||||
|
||||
$visibility = array();
|
||||
$visibility = [];
|
||||
|
||||
// If the block is assigned to specific roles, add the user_role condition.
|
||||
if ($roles) {
|
||||
$visibility['user_role'] = array(
|
||||
$visibility['user_role'] = [
|
||||
'id' => 'user_role',
|
||||
'roles' => array(),
|
||||
'context_mapping' => array(
|
||||
'roles' => [],
|
||||
'context_mapping' => [
|
||||
'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);
|
||||
|
@ -104,12 +104,12 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
|
|||
if ($old_visibility == 2) {
|
||||
// If the PHP module is present, migrate the visibility code unaltered.
|
||||
if ($this->moduleHandler->moduleExists('php')) {
|
||||
$visibility['php'] = array(
|
||||
$visibility['php'] = [
|
||||
'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
|
||||
|
@ -123,11 +123,11 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
|
|||
foreach ($paths as $key => $path) {
|
||||
$paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
|
||||
}
|
||||
$visibility['request_path'] = array(
|
||||
$visibility['request_path'] = [
|
||||
'id' => 'request_path',
|
||||
'negate' => !$old_visibility,
|
||||
'pages' => implode("\n", $paths),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ class Block extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'bid' => $this->t('The block numeric identifier.'),
|
||||
'module' => $this->t('The module providing the block.'),
|
||||
'delta' => $this->t('The block\'s delta.'),
|
||||
|
@ -93,7 +93,7 @@ class Block extends DrupalSqlBase {
|
|||
'pages' => $this->t('Pages list.'),
|
||||
'title' => $this->t('Block title.'),
|
||||
'cache' => $this->t('Cache rule.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ class Block extends DrupalSqlBase {
|
|||
$delta = $row->getSourceProperty('delta');
|
||||
|
||||
$query = $this->select($this->blockRoleTable, 'br')
|
||||
->fields('br', array('rid'))
|
||||
->fields('br', ['rid'])
|
||||
->condition('module', $module)
|
||||
->condition('delta', $delta);
|
||||
$query->join($this->userRoleTable, 'ur', 'br.rid = ur.rid');
|
||||
|
@ -125,7 +125,7 @@ class Block extends DrupalSqlBase {
|
|||
->fetchCol();
|
||||
$row->setSourceProperty('roles', $roles);
|
||||
|
||||
$settings = array();
|
||||
$settings = [];
|
||||
switch ($module) {
|
||||
case 'aggregator':
|
||||
list($type, $id) = explode('-', $delta);
|
||||
|
@ -152,7 +152,7 @@ class Block extends DrupalSqlBase {
|
|||
$settings['forum']['block_num'] = $this->variableGet('forum_block_num_' . $delta, 5);
|
||||
break;
|
||||
case 'statistics':
|
||||
foreach (array('statistics_block_top_day_num', 'statistics_block_top_all_num', 'statistics_block_top_last_num') as $name) {
|
||||
foreach (['statistics_block_top_day_num', 'statistics_block_top_all_num', 'statistics_block_top_last_num'] as $name) {
|
||||
$settings['statistics'][$name] = $this->variableGet($name, 0);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -16,14 +16,14 @@ class BlockAdminThemeTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'contextual');
|
||||
public static $modules = ['block', 'contextual'];
|
||||
|
||||
/**
|
||||
* Check for the accessibility of the admin theme on the block admin page.
|
||||
*/
|
||||
function testAdminTheme() {
|
||||
public function testAdminTheme() {
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes'));
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks', 'administer themes']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Ensure that access to block admin page is denied when theme is not
|
||||
|
@ -32,7 +32,7 @@ class BlockAdminThemeTest extends WebTestBase {
|
|||
$this->assertResponse(403);
|
||||
|
||||
// Install admin theme and confirm that tab is accessible.
|
||||
\Drupal::service('theme_handler')->install(array('bartik'));
|
||||
\Drupal::service('theme_handler')->install(['bartik']);
|
||||
$edit['admin_theme'] = 'bartik';
|
||||
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
|
||||
$this->drupalGet('admin/structure/block/list/bartik');
|
||||
|
@ -42,7 +42,7 @@ class BlockAdminThemeTest extends WebTestBase {
|
|||
/**
|
||||
* Ensure contextual links are disabled in Seven theme.
|
||||
*/
|
||||
function testSevenAdminTheme() {
|
||||
public function testSevenAdminTheme() {
|
||||
// Create administrative user.
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace Drupal\block\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests form in block caching.
|
||||
*
|
||||
|
@ -31,7 +33,7 @@ class BlockFormInBlockTest extends WebTestBase {
|
|||
/**
|
||||
* Test to see if form in block's redirect isn't cached.
|
||||
*/
|
||||
function testCachePerPage() {
|
||||
public function testCachePerPage() {
|
||||
$form_values = ['email' => 'test@example.com'];
|
||||
|
||||
// Go to "test-page" and test if the block is enabled.
|
||||
|
@ -64,7 +66,7 @@ class BlockFormInBlockTest extends WebTestBase {
|
|||
public function testPlaceholders() {
|
||||
$this->drupalGet('test-multiple-forms');
|
||||
|
||||
$placeholder = 'form_action_' . hash('crc32b', 'Drupal\Core\Form\FormBuilder::prepareForm');
|
||||
$placeholder = 'form_action_' . Crypt::hashBase64('Drupal\Core\Form\FormBuilder::prepareForm');
|
||||
$this->assertText('Form action: ' . $placeholder, 'placeholder found.');
|
||||
}
|
||||
|
||||
|
|
|
@ -18,25 +18,25 @@ class BlockLanguageCacheTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'language', 'menu_ui');
|
||||
public static $modules = ['block', 'language', 'menu_ui'];
|
||||
|
||||
/**
|
||||
* List of langcodes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $langcodes = array();
|
||||
protected $langcodes = [];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create test languages.
|
||||
$this->langcodes = array(ConfigurableLanguage::load('en'));
|
||||
$this->langcodes = [ConfigurableLanguage::load('en')];
|
||||
for ($i = 1; $i < 3; ++$i) {
|
||||
$language = ConfigurableLanguage::create(array(
|
||||
$language = ConfigurableLanguage::create([
|
||||
'id' => 'l' . $i,
|
||||
'label' => $this->randomString(),
|
||||
));
|
||||
]);
|
||||
$language->save();
|
||||
$this->langcodes[$i] = $language;
|
||||
}
|
||||
|
@ -47,16 +47,16 @@ class BlockLanguageCacheTest extends WebTestBase {
|
|||
*/
|
||||
public function testBlockLinks() {
|
||||
// Create admin user to be able to access block admin.
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access administration pages',
|
||||
'administer menu',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create the block cache for all languages.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$this->drupalGet('admin/structure/block', array('language' => $langcode));
|
||||
$this->drupalGet('admin/structure/block', ['language' => $langcode]);
|
||||
$this->clickLinkPartialName('Place block');
|
||||
}
|
||||
|
||||
|
@ -64,11 +64,11 @@ class BlockLanguageCacheTest extends WebTestBase {
|
|||
$edit['label'] = $this->randomMachineName();
|
||||
$edit['id'] = Unicode::strtolower($edit['label']);
|
||||
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
|
||||
$this->assertText(t('Menu @label has been added.', array('@label' => $edit['label'])));
|
||||
$this->assertText(t('Menu @label has been added.', ['@label' => $edit['label']]));
|
||||
|
||||
// Check that the block is listed for all languages.
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
$this->drupalGet('admin/structure/block', array('language' => $langcode));
|
||||
$this->drupalGet('admin/structure/block', ['language' => $langcode]);
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->assertText($edit['label']);
|
||||
}
|
||||
|
|
|
@ -17,49 +17,49 @@ class BlockRenderOrderTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'block');
|
||||
public static $modules = ['node', 'block'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Create a test user.
|
||||
$end_user = $this->drupalCreateUser(array(
|
||||
$end_user = $this->drupalCreateUser([
|
||||
'access content',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($end_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the render order of the blocks.
|
||||
*/
|
||||
function testBlockRenderOrder() {
|
||||
public function testBlockRenderOrder() {
|
||||
// Enable test blocks and place them in the same region.
|
||||
$region = 'header';
|
||||
$test_blocks = array(
|
||||
'stark_powered' => array(
|
||||
$test_blocks = [
|
||||
'stark_powered' => [
|
||||
'weight' => '-3',
|
||||
'id' => 'stark_powered',
|
||||
'label' => 'Test block A',
|
||||
),
|
||||
'stark_by' => array(
|
||||
],
|
||||
'stark_by' => [
|
||||
'weight' => '3',
|
||||
'id' => 'stark_by',
|
||||
'label' => 'Test block C',
|
||||
),
|
||||
'stark_drupal' => array(
|
||||
],
|
||||
'stark_drupal' => [
|
||||
'weight' => '3',
|
||||
'id' => 'stark_drupal',
|
||||
'label' => 'Test block B',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Place the test blocks.
|
||||
foreach ($test_blocks as $test_block) {
|
||||
$this->drupalPlaceBlock('system_powered_by_block', array(
|
||||
$this->drupalPlaceBlock('system_powered_by_block', [
|
||||
'label' => $test_block['label'],
|
||||
'region' => $region,
|
||||
'weight' => $test_block['weight'],
|
||||
'id' => $test_block['id'],
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
$this->drupalGet('');
|
||||
|
|
|
@ -14,7 +14,7 @@ class BlockSystemBrandingTest extends BlockTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'system');
|
||||
public static $modules = ['block', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -26,7 +26,7 @@ class BlockSystemBrandingTest extends BlockTestBase {
|
|||
->set('slogan', 'Community plumbing')
|
||||
->save();
|
||||
// Add the system branding block to the page.
|
||||
$this->drupalPlaceBlock('system_branding_block', array('region' => 'header', 'id' => 'site-branding'));
|
||||
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header', 'id' => 'site-branding']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,18 +18,18 @@ class BlockTest extends BlockTestBase {
|
|||
/**
|
||||
* Tests block visibility.
|
||||
*/
|
||||
function testBlockVisibility() {
|
||||
public function testBlockVisibility() {
|
||||
$block_name = 'system_powered_by_block';
|
||||
// Create a random title for the block.
|
||||
$title = $this->randomMachineName(8);
|
||||
// Enable a standard block.
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'region' => 'sidebar_first',
|
||||
'settings[label]' => $title,
|
||||
'settings[label_display]' => TRUE,
|
||||
);
|
||||
];
|
||||
// Set the block to be hidden on any user path, and to be shown only to
|
||||
// authenticated users.
|
||||
$edit['visibility[request_path][pages]'] = '/user*';
|
||||
|
@ -69,11 +69,11 @@ class BlockTest extends BlockTestBase {
|
|||
$title = $this->randomMachineName(8);
|
||||
// Enable a standard block.
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'region' => 'sidebar_first',
|
||||
'settings[label]' => $title,
|
||||
);
|
||||
];
|
||||
$block_id = $edit['id'];
|
||||
// Set the block to be shown only to authenticated users.
|
||||
$edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE;
|
||||
|
@ -99,18 +99,18 @@ class BlockTest extends BlockTestBase {
|
|||
/**
|
||||
* Test block visibility when leaving "pages" textarea empty.
|
||||
*/
|
||||
function testBlockVisibilityListedEmpty() {
|
||||
public function testBlockVisibilityListedEmpty() {
|
||||
$block_name = 'system_powered_by_block';
|
||||
// Create a random title for the block.
|
||||
$title = $this->randomMachineName(8);
|
||||
// Enable a standard block.
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'region' => 'sidebar_first',
|
||||
'settings[label]' => $title,
|
||||
'visibility[request_path][negate]' => TRUE,
|
||||
);
|
||||
];
|
||||
// Set the block to be hidden on any user path, and to be shown only to
|
||||
// authenticated users.
|
||||
$this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
|
||||
|
@ -176,12 +176,16 @@ class BlockTest extends BlockTestBase {
|
|||
/**
|
||||
* Test configuring and moving a module-define block to specific regions.
|
||||
*/
|
||||
function testBlock() {
|
||||
public function testBlock() {
|
||||
// Place page title block to test error messages.
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Disable the block.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLink('Disable');
|
||||
|
||||
// Select the 'Powered by Drupal' block to be configured and moved.
|
||||
$block = array();
|
||||
$block = [];
|
||||
$block['id'] = 'system_powered_by_block';
|
||||
$block['settings[label]'] = $this->randomMachineName(8);
|
||||
$block['settings[label_display]'] = TRUE;
|
||||
|
@ -189,7 +193,7 @@ class BlockTest extends BlockTestBase {
|
|||
$block['region'] = 'header';
|
||||
|
||||
// Set block title to confirm that interface works and override any custom titles.
|
||||
$this->drupalPostForm('admin/structure/block/add/' . $block['id'] . '/' . $block['theme'], array('settings[label]' => $block['settings[label]'], 'settings[label_display]' => $block['settings[label_display]'], 'id' => $block['id'], 'region' => $block['region']), t('Save block'));
|
||||
$this->drupalPostForm('admin/structure/block/add/' . $block['id'] . '/' . $block['theme'], ['settings[label]' => $block['settings[label]'], 'settings[label_display]' => $block['settings[label_display]'], 'id' => $block['id'], 'region' => $block['region']], t('Save block'));
|
||||
$this->assertText(t('The block configuration has been saved.'), 'Block title set.');
|
||||
// Check to see if the block was created by checking its configuration.
|
||||
$instance = Block::load($block['id']);
|
||||
|
@ -201,36 +205,35 @@ class BlockTest extends BlockTestBase {
|
|||
$this->moveBlockToRegion($block, $region);
|
||||
}
|
||||
|
||||
// Set the block to the disabled region.
|
||||
$edit = array();
|
||||
$edit['blocks[' . $block['id'] . '][region]'] = -1;
|
||||
$this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
|
||||
// Disable the block.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLink('Disable');
|
||||
|
||||
// Confirm that the block is now listed as disabled.
|
||||
$this->assertText(t('The block settings have been updated.'), 'Block successfully move to disabled region.');
|
||||
$this->assertText(t('The block settings have been updated.'), 'Block successfully moved to disabled region.');
|
||||
|
||||
// Confirm that the block instance title and markup are not displayed.
|
||||
$this->drupalGet('node');
|
||||
$this->assertNoText(t($block['settings[label]']));
|
||||
// Check for <div id="block-my-block-instance-name"> if the machine name
|
||||
// is my_block_instance_name.
|
||||
$xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))));
|
||||
$xpath = $this->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]);
|
||||
$this->assertNoFieldByXPath($xpath, FALSE, 'Block found in no regions.');
|
||||
|
||||
// Test deleting the block from the edit form.
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block['id']);
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the block %name?', array('%name' => $block['settings[label]'])));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The block %name has been deleted.', array('%name' => $block['settings[label]'])));
|
||||
$this->clickLink(t('Remove block'));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block['settings[label]']]));
|
||||
$this->drupalPostForm(NULL, [], t('Remove'));
|
||||
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block['settings[label]']]));
|
||||
|
||||
// Test deleting a block via "Configure block" link.
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block');
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block->id(), array('query' => array('destination' => 'admin')));
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the block %name?', array('%name' => $block->label())));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The block %name has been deleted.', array('%name' => $block->label())));
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block->id(), ['query' => ['destination' => 'admin']]);
|
||||
$this->clickLink(t('Remove block'));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block->label()]));
|
||||
$this->drupalPostForm(NULL, [], t('Remove'));
|
||||
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block->label()]));
|
||||
$this->assertUrl('admin');
|
||||
$this->assertNoRaw($block->id());
|
||||
}
|
||||
|
@ -246,7 +249,7 @@ class BlockTest extends BlockTestBase {
|
|||
$this->drupalGet('admin/structure/block/list/' . $theme);
|
||||
$this->assertTitle(t('Block layout') . ' | Drupal');
|
||||
// Select the 'Powered by Drupal' block to be placed.
|
||||
$block = array();
|
||||
$block = [];
|
||||
$block['id'] = strtolower($this->randomMachineName());
|
||||
$block['theme'] = $theme;
|
||||
$block['region'] = 'content';
|
||||
|
@ -257,7 +260,7 @@ class BlockTest extends BlockTestBase {
|
|||
// Set the default theme and ensure the block is placed.
|
||||
$theme_settings->set('default', $theme)->save();
|
||||
$this->drupalGet('');
|
||||
$elements = $this->xpath('//div[@id = :id]', array(':id' => Html::getUniqueId('block-' . $block['id'])));
|
||||
$elements = $this->xpath('//div[@id = :id]', [':id' => Html::getUniqueId('block-' . $block['id'])]);
|
||||
$this->assertTrue(!empty($elements), 'The block was found.');
|
||||
}
|
||||
}
|
||||
|
@ -265,13 +268,13 @@ class BlockTest extends BlockTestBase {
|
|||
/**
|
||||
* Test block display of theme titles.
|
||||
*/
|
||||
function testThemeName() {
|
||||
public function testThemeName() {
|
||||
// Enable the help block.
|
||||
$this->drupalPlaceBlock('help_block', array('region' => 'help'));
|
||||
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
// Explicitly set the default and admin themes.
|
||||
$theme = 'block_test_specialchars_theme';
|
||||
\Drupal::service('theme_handler')->install(array($theme));
|
||||
\Drupal::service('theme_handler')->install([$theme]);
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->assertEscaped('<"Cat" & \'Mouse\'>');
|
||||
|
@ -282,27 +285,27 @@ class BlockTest extends BlockTestBase {
|
|||
/**
|
||||
* Test block title display settings.
|
||||
*/
|
||||
function testHideBlockTitle() {
|
||||
public function testHideBlockTitle() {
|
||||
$block_name = 'system_powered_by_block';
|
||||
// Create a random title for the block.
|
||||
$title = $this->randomMachineName(8);
|
||||
$id = strtolower($this->randomMachineName(8));
|
||||
// Enable a standard block.
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => $id,
|
||||
'region' => 'sidebar_first',
|
||||
'settings[label]' => $title,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
|
||||
$this->assertText('The block configuration has been saved.', 'Block was saved');
|
||||
|
||||
$this->drupalGet('user');
|
||||
$this->assertNoText($title, 'Block title was not displayed by default.');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'settings[label_display]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/block/manage/' . $id, $edit, t('Save block'));
|
||||
$this->assertText('The block configuration has been saved.', 'Block was saved');
|
||||
|
||||
|
@ -325,26 +328,26 @@ class BlockTest extends BlockTestBase {
|
|||
* The machine name of the theme region to move the block to, for example
|
||||
* 'header' or 'sidebar_first'.
|
||||
*/
|
||||
function moveBlockToRegion(array $block, $region) {
|
||||
public function moveBlockToRegion(array $block, $region) {
|
||||
// Set the created block to a specific region.
|
||||
$block += array('theme' => $this->config('system.theme')->get('default'));
|
||||
$edit = array();
|
||||
$block += ['theme' => $this->config('system.theme')->get('default')];
|
||||
$edit = [];
|
||||
$edit['blocks[' . $block['id'] . '][region]'] = $region;
|
||||
$this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
|
||||
|
||||
// Confirm that the block was moved to the proper region.
|
||||
$this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', array( '%region_name' => $region)));
|
||||
$this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', [ '%region_name' => $region]));
|
||||
|
||||
// Confirm that the block is being displayed.
|
||||
$this->drupalGet('');
|
||||
$this->assertText(t($block['settings[label]']), 'Block successfully being displayed on the page.');
|
||||
|
||||
// Confirm that the custom block was found at the proper region.
|
||||
$xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
|
||||
$xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', [
|
||||
':region-class' => 'region region-' . Html::getClass($region),
|
||||
':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])),
|
||||
));
|
||||
$this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', array('%region_name' => Html::getClass($region))));
|
||||
]);
|
||||
$this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', ['%region_name' => Html::getClass($region)]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,7 +367,7 @@ class BlockTest extends BlockTestBase {
|
|||
$config->save();
|
||||
|
||||
// Place the "Powered by Drupal" block.
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block', array('id' => 'powered'));
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block', ['id' => 'powered']);
|
||||
|
||||
// Prime the page cache.
|
||||
$this->drupalGet('<front>');
|
||||
|
@ -374,25 +377,26 @@ class BlockTest extends BlockTestBase {
|
|||
// both the page and block caches.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
|
||||
$cid_parts = array(\Drupal::url('<front>', array(), array('absolute' => TRUE)), 'html');
|
||||
$cid_parts = [\Drupal::url('<front>', [], ['absolute' => TRUE]), 'html'];
|
||||
$cid = implode(':', $cid_parts);
|
||||
$cache_entry = \Drupal::cache('render')->get($cid);
|
||||
$expected_cache_tags = array(
|
||||
$expected_cache_tags = [
|
||||
'config:block_list',
|
||||
'block_view',
|
||||
'config:block.block.powered',
|
||||
'config:user.role.anonymous',
|
||||
'http_response',
|
||||
'rendered',
|
||||
);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$keys = \Drupal::service('cache_contexts_manager')->convertTokensToKeys(['languages:language_interface', 'theme', 'user.permissions'])->getKeys();
|
||||
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
|
||||
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:' . implode(':', $keys));
|
||||
$expected_cache_tags = array(
|
||||
$expected_cache_tags = [
|
||||
'block_view',
|
||||
'config:block.block.powered',
|
||||
'rendered',
|
||||
);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
|
||||
|
||||
|
@ -407,40 +411,41 @@ class BlockTest extends BlockTestBase {
|
|||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
|
||||
|
||||
// Place the "Powered by Drupal" block another time; verify a cache miss.
|
||||
$block_2 = $this->drupalPlaceBlock('system_powered_by_block', array('id' => 'powered-2'));
|
||||
$block_2 = $this->drupalPlaceBlock('system_powered_by_block', ['id' => 'powered-2']);
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
|
||||
|
||||
// Verify a cache hit, but also the presence of the correct cache tags.
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
|
||||
$cid_parts = array(\Drupal::url('<front>', array(), array('absolute' => TRUE)), 'html');
|
||||
$cid_parts = [\Drupal::url('<front>', [], ['absolute' => TRUE]), 'html'];
|
||||
$cid = implode(':', $cid_parts);
|
||||
$cache_entry = \Drupal::cache('render')->get($cid);
|
||||
$expected_cache_tags = array(
|
||||
$expected_cache_tags = [
|
||||
'config:block_list',
|
||||
'block_view',
|
||||
'config:block.block.powered',
|
||||
'config:block.block.powered-2',
|
||||
'config:user.role.anonymous',
|
||||
'http_response',
|
||||
'rendered',
|
||||
);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$this->assertEqual($cache_entry->tags, $expected_cache_tags);
|
||||
$expected_cache_tags = array(
|
||||
$expected_cache_tags = [
|
||||
'block_view',
|
||||
'config:block.block.powered',
|
||||
'rendered',
|
||||
);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$keys = \Drupal::service('cache_contexts_manager')->convertTokensToKeys(['languages:language_interface', 'theme', 'user.permissions'])->getKeys();
|
||||
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered:' . implode(':', $keys));
|
||||
$this->assertIdentical($cache_entry->tags, $expected_cache_tags);
|
||||
$expected_cache_tags = array(
|
||||
$expected_cache_tags = [
|
||||
'block_view',
|
||||
'config:block.block.powered-2',
|
||||
'rendered',
|
||||
);
|
||||
];
|
||||
sort($expected_cache_tags);
|
||||
$keys = \Drupal::service('cache_contexts_manager')->convertTokensToKeys(['languages:language_interface', 'theme', 'user.permissions'])->getKeys();
|
||||
$cache_entry = \Drupal::cache('render')->get('entity_view:block:powered-2:' . implode(':', $keys));
|
||||
|
@ -451,7 +456,7 @@ class BlockTest extends BlockTestBase {
|
|||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
|
||||
|
||||
// Delete the "Powered by Drupal" blocks; verify a cache miss.
|
||||
entity_delete_multiple('block', array('powered', 'powered-2'));
|
||||
entity_delete_multiple('block', ['powered', 'powered-2']);
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
|
||||
}
|
||||
|
@ -480,12 +485,12 @@ class BlockTest extends BlockTestBase {
|
|||
$theme_handler = \Drupal::service('theme_handler');
|
||||
|
||||
$theme_handler->install(['seven']);
|
||||
$theme_handler->setDefault('seven');
|
||||
$this->config('system.theme')->set('default', 'seven')->save();
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block', ['theme' => 'seven', 'region' => 'help']);
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertText('Powered by Drupal');
|
||||
|
||||
$theme_handler->setDefault('classy');
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
$theme_handler->uninstall(['seven']);
|
||||
|
||||
// Ensure that the block configuration does not exist anymore.
|
||||
|
|
|
@ -15,7 +15,7 @@ abstract class BlockTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'filter', 'test_page_test', 'help', 'block_test');
|
||||
public static $modules = ['block', 'filter', 'test_page_test', 'help', 'block_test'];
|
||||
|
||||
/**
|
||||
* A list of theme regions to test.
|
||||
|
@ -38,31 +38,31 @@ abstract class BlockTestBase extends WebTestBase {
|
|||
$this->config('system.site')->set('page.front', '/test-page')->save();
|
||||
|
||||
// Create Full HTML text format.
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
$full_html_format = FilterFormat::create([
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
));
|
||||
]);
|
||||
$full_html_format->save();
|
||||
|
||||
// Create and log in an administrative user having access to the Full HTML
|
||||
// text format.
|
||||
$this->adminUser = $this->drupalCreateUser(array(
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
$full_html_format->getPermissionName(),
|
||||
'access administration pages',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Define the existing regions.
|
||||
$this->regions = array(
|
||||
$this->regions = [
|
||||
'header',
|
||||
'sidebar_first',
|
||||
'content',
|
||||
'sidebar_second',
|
||||
'footer',
|
||||
);
|
||||
];
|
||||
$block_storage = $this->container->get('entity_type.manager')->getStorage('block');
|
||||
$blocks = $block_storage->loadByProperties(array('theme' => $this->config('system.theme')->get('default')));
|
||||
$blocks = $block_storage->loadByProperties(['theme' => $this->config('system.theme')->get('default')]);
|
||||
foreach ($blocks as $block) {
|
||||
$block->delete();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class BlockUiTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test', 'help', 'condition_test');
|
||||
public static $modules = ['block', 'block_test', 'help', 'condition_test'];
|
||||
|
||||
protected $regions;
|
||||
|
||||
|
@ -43,30 +43,30 @@ class BlockUiTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Create and log in an administrative user.
|
||||
$this->adminUser = $this->drupalCreateUser(array(
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access administration pages',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Enable some test blocks.
|
||||
$this->blockValues = array(
|
||||
array(
|
||||
$this->blockValues = [
|
||||
[
|
||||
'label' => 'Tools',
|
||||
'tr' => '5',
|
||||
'plugin_id' => 'system_menu_block:tools',
|
||||
'settings' => array('region' => 'sidebar_second', 'id' => 'tools'),
|
||||
'settings' => ['region' => 'sidebar_second', 'id' => 'tools'],
|
||||
'test_weight' => '-1',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'label' => 'Powered by Drupal',
|
||||
'tr' => '16',
|
||||
'plugin_id' => 'system_powered_by_block',
|
||||
'settings' => array('region' => 'footer', 'id' => 'powered'),
|
||||
'settings' => ['region' => 'footer', 'id' => 'powered'],
|
||||
'test_weight' => '0',
|
||||
),
|
||||
);
|
||||
$this->blocks = array();
|
||||
],
|
||||
];
|
||||
$this->blocks = [];
|
||||
foreach ($this->blockValues as $values) {
|
||||
$this->blocks[] = $this->drupalPlaceBlock($values['plugin_id'], $values['settings']);
|
||||
}
|
||||
|
@ -76,13 +76,13 @@ class BlockUiTest extends WebTestBase {
|
|||
* Test block demo page exists and functions correctly.
|
||||
*/
|
||||
public function testBlockDemoUiPage() {
|
||||
$this->drupalPlaceBlock('help_block', array('region' => 'help'));
|
||||
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$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->clickLink(t('Demonstrate block regions (@theme)', ['@theme' => 'Classy']));
|
||||
$elements = $this->xpath('//div[contains(@class, "region-highlighted")]/div[contains(@class, "block-region") and contains(text(), :title)]', [':title' => 'Highlighted']);
|
||||
$this->assertTrue(!empty($elements), 'Block demo regions are shown.');
|
||||
|
||||
\Drupal::service('theme_handler')->install(array('test_theme'));
|
||||
\Drupal::service('theme_handler')->install(['test_theme']);
|
||||
$this->drupalGet('admin/structure/block/demo/test_theme');
|
||||
$this->assertEscaped('<strong>Test theme</strong>');
|
||||
|
||||
|
@ -94,7 +94,7 @@ class BlockUiTest extends WebTestBase {
|
|||
/**
|
||||
* Test block admin page exists and functions correctly.
|
||||
*/
|
||||
function testBlockAdminUiPage() {
|
||||
public function testBlockAdminUiPage() {
|
||||
// Visit the blocks admin ui.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
// Look for the blocks table.
|
||||
|
@ -163,11 +163,11 @@ class BlockUiTest extends WebTestBase {
|
|||
* Tests the block categories on the listing page.
|
||||
*/
|
||||
public function testCandidateBlockList() {
|
||||
$arguments = array(
|
||||
$arguments = [
|
||||
':title' => 'Display message',
|
||||
':category' => 'Block test',
|
||||
':href' => 'admin/structure/block/add/test_block_instantiation/classy',
|
||||
);
|
||||
];
|
||||
$pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]';
|
||||
|
||||
$this->drupalGet('admin/structure/block');
|
||||
|
@ -190,11 +190,11 @@ class BlockUiTest extends WebTestBase {
|
|||
* Tests the behavior of unsatisfied context-aware blocks.
|
||||
*/
|
||||
public function testContextAwareUnsatisfiedBlocks() {
|
||||
$arguments = array(
|
||||
$arguments = [
|
||||
':category' => 'Block test',
|
||||
':href' => 'admin/structure/block/add/test_context_aware_unsatisfied/classy',
|
||||
':text' => 'Test context-aware unsatisfied block',
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLinkPartialName('Place block');
|
||||
|
@ -215,11 +215,11 @@ class BlockUiTest extends WebTestBase {
|
|||
$this->assertNoRaw($expected_text);
|
||||
|
||||
$block_url = 'admin/structure/block/add/test_context_aware/classy';
|
||||
$arguments = array(
|
||||
$arguments = [
|
||||
':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');
|
||||
|
@ -230,7 +230,7 @@ class BlockUiTest extends WebTestBase {
|
|||
$this->assertTrue(!empty($definition), 'The context-aware test block exists.');
|
||||
$edit = [
|
||||
'region' => 'content',
|
||||
'settings[context_mapping][user]' => '@block_test.multiple_static_context:user2',
|
||||
'settings[context_mapping][user]' => '@block_test.multiple_static_context:userB',
|
||||
];
|
||||
$this->drupalPostForm($block_url, $edit, 'Save block');
|
||||
|
||||
|
@ -262,12 +262,15 @@ class BlockUiTest extends WebTestBase {
|
|||
$url = 'admin/structure/block/add/test_block_instantiation/classy';
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldByName('id', 'displaymessage', 'Block form uses raw machine name suggestion when no instance already exists.');
|
||||
$this->drupalPostForm($url, array(), 'Save block');
|
||||
$edit = ['region' => 'content'];
|
||||
$this->drupalPostForm($url, $edit, 'Save block');
|
||||
$this->assertText('The block configuration has been saved.');
|
||||
|
||||
// Now, check to make sure the form starts by autoincrementing correctly.
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldByName('id', 'displaymessage_2', 'Block form appends _2 to plugin-suggested machine name when an instance already exists.');
|
||||
$this->drupalPostForm($url, array(), 'Save block');
|
||||
$this->drupalPostForm($url, $edit, 'Save block');
|
||||
$this->assertText('The block configuration has been saved.');
|
||||
|
||||
// And verify that it continues working beyond just the first two.
|
||||
$this->drupalGet($url);
|
||||
|
@ -279,7 +282,7 @@ class BlockUiTest extends WebTestBase {
|
|||
*/
|
||||
public function testBlockPlacementIndicator() {
|
||||
// Select the 'Powered by Drupal' block to be placed.
|
||||
$block = array();
|
||||
$block = [];
|
||||
$block['id'] = strtolower($this->randomMachineName());
|
||||
$block['theme'] = 'classy';
|
||||
$block['region'] = 'content';
|
||||
|
@ -289,7 +292,7 @@ class BlockUiTest extends WebTestBase {
|
|||
$this->assertUrl('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
|
||||
|
||||
// Resaving the block page will remove the block indicator.
|
||||
$this->drupalPostForm(NULL, array(), t('Save blocks'));
|
||||
$this->drupalPostForm(NULL, [], t('Save blocks'));
|
||||
$this->assertUrl('admin/structure/block/list/classy');
|
||||
}
|
||||
|
||||
|
@ -297,7 +300,7 @@ class BlockUiTest extends WebTestBase {
|
|||
* Tests if validation errors are passed plugin form to the parent form.
|
||||
*/
|
||||
public function testBlockValidateErrors() {
|
||||
$this->drupalPostForm('admin/structure/block/add/test_settings_validation/classy', ['settings[digits]' => 'abc'], t('Save block'));
|
||||
$this->drupalPostForm('admin/structure/block/add/test_settings_validation/classy', ['region' => 'content', 'settings[digits]' => 'abc'], t('Save block'));
|
||||
|
||||
$arguments = [':message' => 'Only digits are allowed'];
|
||||
$pattern = '//div[contains(@class,"messages messages--error")]/div[contains(text()[2],:message)]';
|
||||
|
@ -309,4 +312,18 @@ class BlockUiTest extends WebTestBase {
|
|||
$this->assertTrue($error_class, 'Plugin error class found in parent form.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the enable/disable routes are protected from CSRF.
|
||||
*/
|
||||
public function testRouteProtection() {
|
||||
// Get the first block generated in our setUp method.
|
||||
/** @var \Drupal\block\BlockInterface $block */
|
||||
$block = reset($this->blocks);
|
||||
// Ensure that the enable and disable routes are protected.
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block->id() . '/disable');
|
||||
$this->assertResponse(403);
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block->id() . '/enable');
|
||||
$this->assertResponse(403);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class NonDefaultBlockAdminTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -30,11 +30,11 @@ class NonDefaultBlockAdminTest extends WebTestBase {
|
|||
/**
|
||||
* Test non-default theme admin.
|
||||
*/
|
||||
function testNonDefaultBlockAdmin() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes'));
|
||||
public function testNonDefaultBlockAdmin() {
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks', 'administer themes']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$new_theme = 'bartik';
|
||||
\Drupal::service('theme_handler')->install(array($new_theme));
|
||||
\Drupal::service('theme_handler')->install([$new_theme]);
|
||||
$this->drupalGet('admin/structure/block/list/' . $new_theme);
|
||||
$this->assertText('Bartik(' . t('active tab') . ')', 'Tab for non-default theme found.');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests the upgrade path for removal of disabled region.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2513534
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class BlockRemoveDisabledRegionUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['block_test', 'language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.update-test-block-disabled-2513534.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that block context mapping is updated properly.
|
||||
*/
|
||||
public function testUpdateHookN() {
|
||||
$this->runUpdates();
|
||||
|
||||
// Disable maintenance mode.
|
||||
\Drupal::state()->set('system.maintenance_mode', FALSE);
|
||||
|
||||
// We finished updating so we can login the user now.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
|
||||
// Verify that a disabled block is in the default region.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
|
||||
[':block' => 'edit-blocks-pagetitle-1', ':status' => 'block-disabled', ':region' => 'header']);
|
||||
$this->assertTrue(!empty($element));
|
||||
|
||||
// Verify that an enabled block is now disabled and in the default region.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
|
||||
[':block' => 'edit-blocks-pagetitle-2', ':status' => 'block-disabled', ':region' => 'header']);
|
||||
$this->assertTrue(!empty($element));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -26,19 +26,19 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'block_test_views', 'test_page_test', 'contextual', 'views_ui');
|
||||
public static $modules = ['node', 'block_test_views', 'test_page_test', 'contextual', 'views_ui'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('test_view_block', 'test_view_block2');
|
||||
public static $testViews = ['test_view_block', 'test_view_block2'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), array('block_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['block_test_views']);
|
||||
$this->enableViewsTestModule();
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
* Tests default and custom block categories.
|
||||
*/
|
||||
public function testBlockCategory() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer views', 'administer blocks')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views', 'administer blocks']));
|
||||
|
||||
// Create a new view in the UI.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['label'] = $this->randomString();
|
||||
$edit['id'] = strtolower($this->randomMachineName());
|
||||
$edit['show[wizard_key]'] = 'standard:views_test_data';
|
||||
|
@ -62,20 +62,20 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
// Test that the block was given a default category corresponding to its
|
||||
// base table.
|
||||
$arguments = array(
|
||||
':href' => \Drupal::Url('block.admin_add', array(
|
||||
$arguments = [
|
||||
':href' => \Drupal::Url('block.admin_add', [
|
||||
'plugin_id' => 'views_block:' . $edit['id'] . '-block_1',
|
||||
'theme' => 'classy',
|
||||
)),
|
||||
]),
|
||||
':category' => t('Lists (Views)'),
|
||||
);
|
||||
];
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$elements = $this->xpath($pattern, $arguments);
|
||||
$this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.');
|
||||
|
||||
// Duplicate the block before changing the category.
|
||||
$this->drupalPostForm('admin/structure/views/view/' . $edit['id'] . '/edit/block_1', array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
|
||||
$this->drupalPostForm('admin/structure/views/view/' . $edit['id'] . '/edit/block_1', [], t('Duplicate @display_title', ['@display_title' => 'Block']));
|
||||
$this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_2');
|
||||
|
||||
// Change the block category to a random string.
|
||||
|
@ -84,13 +84,13 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$this->assertTrue(!empty($link));
|
||||
$this->clickLink(t('Lists (Views)'));
|
||||
$category = $this->randomString();
|
||||
$this->drupalPostForm(NULL, array('block_category' => $category), t('Apply'));
|
||||
$this->drupalPostForm(NULL, ['block_category' => $category], t('Apply'));
|
||||
|
||||
// Duplicate the block after changing the category.
|
||||
$this->drupalPostForm(NULL, array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
|
||||
$this->drupalPostForm(NULL, [], t('Duplicate @display_title', ['@display_title' => 'Block']));
|
||||
$this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_3');
|
||||
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Test that the blocks are listed under the correct categories.
|
||||
$arguments[':category'] = $category;
|
||||
|
@ -99,23 +99,23 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$elements = $this->xpath($pattern, $arguments);
|
||||
$this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
|
||||
|
||||
$arguments = array(
|
||||
':href' => \Drupal::Url('block.admin_add', array(
|
||||
$arguments = [
|
||||
':href' => \Drupal::Url('block.admin_add', [
|
||||
'plugin_id' => 'views_block:' . $edit['id'] . '-block_2',
|
||||
'theme' => 'classy',
|
||||
)),
|
||||
]),
|
||||
':category' => t('Lists (Views)'),
|
||||
);
|
||||
];
|
||||
$elements = $this->xpath($pattern, $arguments);
|
||||
$this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
|
||||
|
||||
$arguments = array(
|
||||
':href' => \Drupal::Url('block.admin_add', array(
|
||||
$arguments = [
|
||||
':href' => \Drupal::Url('block.admin_add', [
|
||||
'plugin_id' => 'views_block:' . $edit['id'] . '-block_3',
|
||||
'theme' => 'classy',
|
||||
)),
|
||||
]),
|
||||
':category' => $category,
|
||||
);
|
||||
];
|
||||
$elements = $this->xpath($pattern, $arguments);
|
||||
$this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.');
|
||||
}
|
||||
|
@ -126,13 +126,13 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
public function testDeleteBlockDisplay() {
|
||||
// To test all combinations possible we first place create two instances
|
||||
// of the block display of the first view.
|
||||
$block_1 = $this->drupalPlaceBlock('views_block:test_view_block-block_1', array('label' => 'test_view_block-block_1:1'));
|
||||
$block_2 = $this->drupalPlaceBlock('views_block:test_view_block-block_1', array('label' => 'test_view_block-block_1:2'));
|
||||
$block_1 = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1']);
|
||||
$block_2 = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:2']);
|
||||
|
||||
// Then we add one instance of blocks for each of the two displays of the
|
||||
// second view.
|
||||
$block_3 = $this->drupalPlaceBlock('views_block:test_view_block2-block_1', array('label' => 'test_view_block2-block_1'));
|
||||
$block_4 = $this->drupalPlaceBlock('views_block:test_view_block2-block_2', array('label' => 'test_view_block2-block_2'));
|
||||
$block_3 = $this->drupalPlaceBlock('views_block:test_view_block2-block_1', ['label' => 'test_view_block2-block_1']);
|
||||
$block_4 = $this->drupalPlaceBlock('views_block:test_view_block2-block_2', ['label' => 'test_view_block2-block_2']);
|
||||
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertBlockAppears($block_1);
|
||||
|
@ -177,7 +177,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
* Test the block form for a Views block.
|
||||
*/
|
||||
public function testViewsBlockForm() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer blocks')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks']));
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
|
||||
$elements = $this->xpath('//input[@name="label"]');
|
||||
|
@ -185,8 +185,10 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
// Test that that machine name field is hidden from display and has been
|
||||
// saved as expected from the default value.
|
||||
$this->assertNoFieldById('edit-machine-name', 'views_block__test_view_block_1', 'The machine name is hidden on the views block form.');
|
||||
|
||||
// Save the block.
|
||||
$this->drupalPostForm(NULL, array(), t('Save block'));
|
||||
$edit = ['region' => 'content'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save block'));
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('block');
|
||||
$block = $storage->load('views_block__test_view_block_block_1');
|
||||
// This will only return a result if our new block has been created with the
|
||||
|
@ -195,7 +197,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
for ($i = 2; $i <= 3; $i++) {
|
||||
// Place the same block again and make sure we have a new ID.
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, array(), t('Save block'));
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
|
||||
$block = $storage->load('views_block__test_view_block_block_1_' . $i);
|
||||
// This will only return a result if our new block has been created with the
|
||||
// expected machine name.
|
||||
|
@ -204,7 +206,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
// Tests the override capability of items per page.
|
||||
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
|
||||
$edit = array();
|
||||
$edit = ['region' => 'content'];
|
||||
$edit['settings[override][items_per_page]'] = 10;
|
||||
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
|
||||
|
@ -222,7 +224,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$this->assertEqual(5, $config['items_per_page'], "'Items per page' is properly saved.");
|
||||
|
||||
// Tests the override of the label capability.
|
||||
$edit = array();
|
||||
$edit = ['region' => 'content'];
|
||||
$edit['settings[views_label_checkbox]'] = 1;
|
||||
$edit['settings[views_label]'] = 'Custom title';
|
||||
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
|
||||
|
@ -237,7 +239,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
*/
|
||||
public function testBlockRendering() {
|
||||
// Create a block and set a custom title.
|
||||
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', array('label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title'));
|
||||
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']);
|
||||
$this->drupalGet('');
|
||||
|
||||
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
|
||||
|
@ -260,7 +262,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
|
||||
$this->assertTrue(empty($result), 'The title is not visible.');
|
||||
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' , 'rendered']));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block' , 'http_response', 'rendered']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,7 +276,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$view = View::load('test_view_block');
|
||||
$view->invalidateCaches();
|
||||
|
||||
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', array('label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title'));
|
||||
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']);
|
||||
$this->drupalGet('');
|
||||
$this->assertEqual(1, count($this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')));
|
||||
|
||||
|
@ -286,7 +288,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$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:views.view.test_view_block' , 'rendered']));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' , 'http_response', 'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Add a header displayed on empty result.
|
||||
|
@ -304,7 +306,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
$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:views.view.test_view_block' , 'rendered']));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block' , 'http_response', 'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Hide the header on empty results.
|
||||
|
@ -322,7 +324,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
$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:views.view.test_view_block' , 'rendered']));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
|
||||
// Add an empty text.
|
||||
|
@ -339,7 +341,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
|
||||
$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:views.view.test_view_block' , 'rendered']));
|
||||
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
|
||||
$this->assertCacheContexts(['url.query_args:_wrapper_format']);
|
||||
}
|
||||
|
||||
|
@ -347,7 +349,7 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
* Tests the contextual links on a Views block.
|
||||
*/
|
||||
public function testBlockContextualLinks() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer views', 'access contextual links', 'administer blocks')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views', 'access contextual links', 'administer blocks']));
|
||||
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1');
|
||||
$cached_block = $this->drupalPlaceBlock('views_block:test_view_block-block_1');
|
||||
$this->drupalGet('test-page');
|
||||
|
@ -355,13 +357,13 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$id = 'block:block=' . $block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
|
||||
$cached_id = 'block:block=' . $cached_block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
|
||||
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
|
||||
$this->assertRaw('<div' . new Attribute(array('data-contextual-id' => $id)) . '></div>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id)));
|
||||
$this->assertRaw('<div' . new Attribute(array('data-contextual-id' => $cached_id)) . '></div>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $cached_id)));
|
||||
$this->assertRaw('<div' . new Attribute(['data-contextual-id' => $id]) . '></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $id]));
|
||||
$this->assertRaw('<div' . new Attribute(['data-contextual-id' => $cached_id]) . '></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $cached_id]));
|
||||
|
||||
// Get server-rendered contextual links.
|
||||
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
|
||||
$post = array('ids[0]' => $id, 'ids[1]' => $cached_id);
|
||||
$response = $this->drupalPostWithFormat('contextual/render', 'json', $post, array('query' => array('destination' => 'test-page')));
|
||||
$post = ['ids[0]' => $id, 'ids[1]' => $cached_id];
|
||||
$response = $this->drupalPostWithFormat('contextual/render', 'json', $post, ['query' => ['destination' => 'test-page']]);
|
||||
$this->assertResponse(200);
|
||||
$json = Json::decode($response);
|
||||
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
|
||||
|
|
|
@ -47,9 +47,9 @@ class MultipleStaticContext implements ContextProviderInterface {
|
|||
public function getRuntimeContexts(array $unqualified_context_ids) {
|
||||
$current_user = $this->userStorage->load($this->account->id());
|
||||
|
||||
$context1 = new Context(new ContextDefinition('entity:user', 'User 1'), $current_user);
|
||||
$context1 = new Context(new ContextDefinition('entity:user', 'User A'), $current_user);
|
||||
|
||||
$context2 = new Context(new ContextDefinition('entity:user', 'User 2'), $current_user);
|
||||
$context2 = new Context(new ContextDefinition('entity:user', 'User B'), $current_user);
|
||||
|
||||
$cacheability = new CacheableMetadata();
|
||||
$cacheability->setCacheContexts(['user']);
|
||||
|
@ -58,8 +58,8 @@ class MultipleStaticContext implements ContextProviderInterface {
|
|||
$context2->addCacheableDependency($cacheability);
|
||||
|
||||
return [
|
||||
'user1' => $context1,
|
||||
'user2' => $context2,
|
||||
'userA' => $context1,
|
||||
'userB' => $context2,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ class TestBlockInstantiation extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'display_message' => 'no message set',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,11 +37,11 @@ class TestBlockInstantiation extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$form['display_message'] = array(
|
||||
$form['display_message'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Display message'),
|
||||
'#default_value' => $this->configuration['display_message'],
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,9 @@ class TestBlockInstantiation extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return array(
|
||||
return [
|
||||
'#children' => $this->configuration['display_message'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class TestCacheBlock extends BlockBase {
|
|||
public function build() {
|
||||
$content = \Drupal::state()->get('block_test.content');
|
||||
|
||||
$build = array();
|
||||
$build = [];
|
||||
if (!empty($content)) {
|
||||
$build['#markup'] = $content;
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ class TestContextAwareBlock extends BlockBase {
|
|||
public function build() {
|
||||
/** @var $user \Drupal\user\UserInterface */
|
||||
$user = $this->getContextValue('user');
|
||||
return array(
|
||||
return [
|
||||
'#prefix' => '<div id="' . $this->getPluginId() . '--username">',
|
||||
'#suffix' => '</div>',
|
||||
'#markup' => $user ? $user->getUsername() : 'No context mapping selected.' ,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,10 +18,10 @@ class TestHtmlBlock extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return array(
|
||||
return [
|
||||
'#attributes' => \Drupal::state()->get('block_test.attributes'),
|
||||
'#children' => \Drupal::state()->get('block_test.content'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,433 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- node
|
||||
- user
|
||||
id: test_view_block_with_context
|
||||
label: test_view_block_with_context
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: node_field_data
|
||||
base_field: nid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
exposed_form:
|
||||
type: basic
|
||||
options:
|
||||
submit_button: Apply
|
||||
reset_button: false
|
||||
reset_button_label: Reset
|
||||
exposed_sorts_label: 'Sort by'
|
||||
expose_sort_order: true
|
||||
sort_asc_label: Asc
|
||||
sort_desc_label: Desc
|
||||
pager:
|
||||
type: some
|
||||
options:
|
||||
items_per_page: 5
|
||||
offset: 0
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
title:
|
||||
id: title
|
||||
table: node_field_data
|
||||
field: title
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: true
|
||||
text: 'Test view row: {{ title }}'
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: false
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings:
|
||||
link_to_entity: true
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
plugin_id: field
|
||||
filters:
|
||||
status:
|
||||
value: '1'
|
||||
table: node_field_data
|
||||
field: status
|
||||
plugin_id: boolean
|
||||
entity_type: node
|
||||
entity_field: status
|
||||
id: status
|
||||
expose:
|
||||
operator: ''
|
||||
group: 1
|
||||
sorts:
|
||||
created:
|
||||
id: created
|
||||
table: node_field_data
|
||||
field: created
|
||||
order: DESC
|
||||
entity_type: node
|
||||
entity_field: created
|
||||
plugin_id: date
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
granularity: second
|
||||
title: test_view_block_with_context
|
||||
header: { }
|
||||
footer: { }
|
||||
empty:
|
||||
area_text_custom:
|
||||
id: area_text_custom
|
||||
table: views
|
||||
field: area_text_custom
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: true
|
||||
tokenize: false
|
||||
content: 'Test view: No results found.'
|
||||
plugin_id: text_custom
|
||||
relationships: { }
|
||||
arguments:
|
||||
'null':
|
||||
id: 'null'
|
||||
table: views
|
||||
field: 'null'
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: default
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: foo
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: false
|
||||
validate:
|
||||
type: none
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
must_not_be: false
|
||||
plugin_id: 'null'
|
||||
null_1:
|
||||
id: null_1
|
||||
table: views
|
||||
field: 'null'
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: ignore
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: false
|
||||
validate:
|
||||
type: none
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
must_not_be: false
|
||||
plugin_id: 'null'
|
||||
nid:
|
||||
id: nid
|
||||
table: node_field_data
|
||||
field: nid
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: empty
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: true
|
||||
validate:
|
||||
type: 'entity:node'
|
||||
fail: 'not found'
|
||||
validate_options:
|
||||
operation: view
|
||||
multiple: 0
|
||||
bundles: { }
|
||||
access: false
|
||||
break_phrase: false
|
||||
not: false
|
||||
entity_type: node
|
||||
entity_field: nid
|
||||
plugin_id: node_nid
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
cacheable: false
|
||||
max-age: -1
|
||||
tags: { }
|
||||
block_1:
|
||||
display_plugin: block
|
||||
id: block_1
|
||||
display_title: Block
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
cacheable: false
|
||||
max-age: -1
|
||||
tags: { }
|
||||
block_2:
|
||||
display_plugin: block
|
||||
id: block_2
|
||||
display_title: 'Block 2'
|
||||
position: 2
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
arguments:
|
||||
created:
|
||||
id: created
|
||||
table: node_field_data
|
||||
field: created
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: ignore
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: true
|
||||
validate:
|
||||
type: numeric
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
entity_type: node
|
||||
entity_field: created
|
||||
plugin_id: date
|
||||
vid:
|
||||
id: vid
|
||||
table: node_field_data
|
||||
field: vid
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: ignore
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: false
|
||||
validate:
|
||||
type: none
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
break_phrase: false
|
||||
not: false
|
||||
entity_type: node
|
||||
entity_field: vid
|
||||
plugin_id: numeric
|
||||
title:
|
||||
id: title
|
||||
table: node_field_data
|
||||
field: title
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
default_action: ignore
|
||||
exception:
|
||||
value: all
|
||||
title_enable: false
|
||||
title: All
|
||||
title_enable: false
|
||||
title: ''
|
||||
default_argument_type: fixed
|
||||
default_argument_options:
|
||||
argument: ''
|
||||
default_argument_skip_url: false
|
||||
summary_options:
|
||||
base_path: ''
|
||||
count: true
|
||||
items_per_page: 25
|
||||
override: false
|
||||
summary:
|
||||
sort_order: asc
|
||||
number_of_records: 0
|
||||
format: default_summary
|
||||
specify_validation: false
|
||||
validate:
|
||||
type: none
|
||||
fail: 'not found'
|
||||
validate_options: { }
|
||||
glossary: false
|
||||
limit: 0
|
||||
case: none
|
||||
path_case: none
|
||||
transform_dash: false
|
||||
break_phrase: false
|
||||
entity_type: node
|
||||
entity_field: title
|
||||
plugin_id: string
|
||||
defaults:
|
||||
arguments: false
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.node_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -1,23 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests block caching.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockCacheTest extends WebTestBase {
|
||||
class BlockCacheTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test', 'test_page_test');
|
||||
public static $modules = ['block', 'block_test', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* A user with permission to create and edit books and to administer blocks.
|
||||
|
@ -51,7 +51,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create an admin user, log in and enable test blocks.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer blocks', 'access administration pages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer blocks', 'access administration pages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create additional users to test caching modes.
|
||||
|
@ -69,7 +69,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
/**
|
||||
* Test "user.roles" cache context.
|
||||
*/
|
||||
function testCachePerRole() {
|
||||
public function testCachePerRole() {
|
||||
\Drupal::state()->set('block_test.cache_contexts', ['user.roles']);
|
||||
|
||||
// Enable our test block. Set some content for it to display.
|
||||
|
@ -87,7 +87,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
$this->assertText($old_content, 'Block is served from the cache.');
|
||||
|
||||
// Clear the cache and verify that the stale data is no longer there.
|
||||
Cache::invalidateTags(array('block_view'));
|
||||
Cache::invalidateTags(['block_view']);
|
||||
$this->drupalGet('');
|
||||
$this->assertNoText($old_content, 'Block cache clear removes stale cache data.');
|
||||
$this->assertText($current_content, 'Fresh block content is displayed after clearing the cache.');
|
||||
|
@ -116,7 +116,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
/**
|
||||
* Test a cacheable block without any additional cache context.
|
||||
*/
|
||||
function testCachePermissions() {
|
||||
public function testCachePermissions() {
|
||||
// user.permissions is a required context, so a user with different
|
||||
// permissions will see a different version of the block.
|
||||
\Drupal::state()->set('block_test.cache_contexts', []);
|
||||
|
@ -142,7 +142,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
/**
|
||||
* Test non-cacheable block.
|
||||
*/
|
||||
function testNoCache() {
|
||||
public function testNoCache() {
|
||||
\Drupal::state()->set('block_test.cache_max_age', 0);
|
||||
|
||||
$current_content = $this->randomMachineName();
|
||||
|
@ -162,7 +162,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
/**
|
||||
* Test "user" cache context.
|
||||
*/
|
||||
function testCachePerUser() {
|
||||
public function testCachePerUser() {
|
||||
\Drupal::state()->set('block_test.cache_contexts', ['user']);
|
||||
|
||||
$current_content = $this->randomMachineName();
|
||||
|
@ -191,7 +191,7 @@ class BlockCacheTest extends WebTestBase {
|
|||
/**
|
||||
* Test "url" cache context.
|
||||
*/
|
||||
function testCachePerPage() {
|
||||
public function testCachePerPage() {
|
||||
\Drupal::state()->set('block_test.cache_contexts', ['url']);
|
||||
|
||||
$current_content = $this->randomMachineName();
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that a newly installed theme does not inherit blocks to its hidden
|
||||
|
@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase;
|
|||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockHiddenRegionTest extends WebTestBase {
|
||||
class BlockHiddenRegionTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* An administrative user to configure the test environment.
|
||||
|
@ -22,17 +22,17 @@ class BlockHiddenRegionTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test', 'search');
|
||||
public static $modules = ['block', 'block_test', 'search'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create administrative user.
|
||||
$this->adminUser = $this->drupalCreateUser(array(
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'administer themes',
|
||||
'search content',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
@ -53,7 +53,7 @@ class BlockHiddenRegionTest extends WebTestBase {
|
|||
$theme = 'block_test_theme';
|
||||
// We need to install a non-hidden theme so that there is more than one
|
||||
// local task.
|
||||
\Drupal::service('theme_handler')->install(array($theme, 'stark'));
|
||||
\Drupal::service('theme_handler')->install([$theme, 'stark']);
|
||||
$this->config('system.theme')
|
||||
->set('default', $theme)
|
||||
->save();
|
|
@ -1,30 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests for Block module regarding hook_entity_operations_alter().
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockHookOperationTest extends WebTestBase {
|
||||
class BlockHookOperationTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'entity_test');
|
||||
public static $modules = ['block', 'entity_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$permissions = array(
|
||||
$permissions = [
|
||||
'administer blocks',
|
||||
);
|
||||
];
|
||||
|
||||
// Create and log in user.
|
||||
$admin_user = $this->drupalCreateUser($permissions);
|
||||
|
@ -38,7 +38,7 @@ class BlockHookOperationTest extends WebTestBase {
|
|||
// Add a test block, any block will do.
|
||||
// Set the machine name so the test_operation link can be built later.
|
||||
$block_id = Unicode::strtolower($this->randomMachineName(16));
|
||||
$this->drupalPlaceBlock('system_powered_by_block', array('id' => $block_id));
|
||||
$this->drupalPlaceBlock('system_powered_by_block', ['id' => $block_id]);
|
||||
|
||||
// Get the Block listing.
|
||||
$this->drupalGet('admin/structure/block');
|
|
@ -1,22 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests block HTML ID validity.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockHtmlTest extends WebTestBase {
|
||||
class BlockHtmlTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test');
|
||||
public static $modules = ['block', 'block_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -24,9 +24,9 @@ class BlockHtmlTest extends WebTestBase {
|
|||
$this->drupalLogin($this->rootUser);
|
||||
|
||||
// Enable the test_html block, to test HTML ID and attributes.
|
||||
\Drupal::state()->set('block_test.attributes', array('data-custom-attribute' => 'foo'));
|
||||
\Drupal::state()->set('block_test.attributes', ['data-custom-attribute' => 'foo']);
|
||||
\Drupal::state()->set('block_test.content', $this->randomMachineName());
|
||||
$this->drupalPlaceBlock('test_html', array('id' => 'test_html_block'));
|
||||
$this->drupalPlaceBlock('test_html', ['id' => 'test_html_block']);
|
||||
|
||||
// Enable a menu block, to test more complicated HTML.
|
||||
$this->drupalPlaceBlock('system_menu_block:admin');
|
||||
|
@ -35,7 +35,7 @@ class BlockHtmlTest extends WebTestBase {
|
|||
/**
|
||||
* Tests for valid HTML for a block.
|
||||
*/
|
||||
function testHtml() {
|
||||
public function testHtml() {
|
||||
$this->drupalGet('');
|
||||
|
||||
// Ensure that a block's ID is converted to an HTML valid ID, and that
|
||||
|
@ -43,7 +43,7 @@ class BlockHtmlTest extends WebTestBase {
|
|||
$this->assertFieldByXPath('//div[@id="block-test-html-block" and @data-custom-attribute="foo"]', NULL, 'HTML ID and attributes for test block are valid and on the same DOM element.');
|
||||
|
||||
// Ensure expected markup for a menu block.
|
||||
$elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', array(':nav-class' => 'block-menu', ':ul-class' => 'menu'));
|
||||
$elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [':nav-class' => 'block-menu', ':ul-class' => 'menu']);
|
||||
$this->assertTrue(!empty($elements), 'The proper block markup was found.');
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\block\Entity\Block;
|
||||
|
||||
/**
|
||||
|
@ -11,52 +11,51 @@ use Drupal\block\Entity\Block;
|
|||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockInvalidRegionTest extends WebTestBase {
|
||||
class BlockInvalidRegionTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test');
|
||||
public static $modules = ['block', 'block_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Create an admin user.
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer site configuration',
|
||||
'access administration pages',
|
||||
'administer blocks',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that blocks assigned to invalid regions work correctly.
|
||||
*/
|
||||
function testBlockInInvalidRegion() {
|
||||
public function testBlockInInvalidRegion() {
|
||||
// Enable a test block and place it in an invalid region.
|
||||
$block = $this->drupalPlaceBlock('test_html');
|
||||
$block->setRegion('invalid_region');
|
||||
$block->save();
|
||||
\Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
|
||||
$block = Block::load($block->id());
|
||||
|
||||
$warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block->id(), '%region' => 'invalid_region'));
|
||||
$warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'invalid_region']);
|
||||
|
||||
// Clearing the cache should disable the test block placed in the invalid region.
|
||||
$this->drupalPostForm('admin/config/development/performance', array(), 'Clear all caches');
|
||||
$this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
||||
$this->assertRaw($warning_message, 'Enabled block was in the invalid region and has been disabled.');
|
||||
|
||||
// Clear the cache to check if the warning message is not triggered.
|
||||
$this->drupalPostForm('admin/config/development/performance', array(), 'Clear all caches');
|
||||
$this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
||||
$this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
|
||||
|
||||
// Place disabled test block in the invalid region of the default theme.
|
||||
\Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
|
||||
$block = Block::load($block->id());
|
||||
$block->setRegion('invalid_region');
|
||||
$block->save();
|
||||
|
||||
// Clear the cache to check if the warning message is not triggered.
|
||||
$this->drupalPostForm('admin/config/development/performance', array(), 'Clear all caches');
|
||||
$this->drupalPostForm('admin/config/development/performance', [], 'Clear all caches');
|
||||
$this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\block\Entity\Block;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ use Drupal\block\Entity\Block;
|
|||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockLanguageTest extends WebTestBase {
|
||||
class BlockLanguageTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* An administrative user to configure the test environment.
|
||||
|
@ -23,19 +23,19 @@ class BlockLanguageTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'block', 'content_translation');
|
||||
public static $modules = ['language', 'block', 'content_translation'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a new user, allow him to manage the blocks and the languages.
|
||||
$this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages'));
|
||||
$this->adminUser = $this->drupalCreateUser(['administer blocks', 'administer languages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Add predefined language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'predefined_langcode' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
$this->assertText('French', 'Language added successfully.');
|
||||
}
|
||||
|
@ -52,17 +52,17 @@ class BlockLanguageTest extends WebTestBase {
|
|||
$this->assertNoField('visibility[language][context_mapping][language]', 'Language type field is not visible.');
|
||||
|
||||
// Enable a standard block and set the visibility setting for one language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'visibility[language][langcodes][en]' => TRUE,
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
|
||||
|
||||
// Change the default language.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
|
||||
|
||||
// Check that a page has a block.
|
||||
|
@ -79,16 +79,16 @@ class BlockLanguageTest extends WebTestBase {
|
|||
*/
|
||||
public function testLanguageBlockVisibilityLanguageDelete() {
|
||||
// Enable a standard block and set the visibility setting for one language.
|
||||
$edit = array(
|
||||
'visibility' => array(
|
||||
'language' => array(
|
||||
'langcodes' => array(
|
||||
$edit = [
|
||||
'visibility' => [
|
||||
'language' => [
|
||||
'langcodes' => [
|
||||
'fr' => 'fr',
|
||||
),
|
||||
],
|
||||
'context_mapping' => ['language' => '@language.current_language_context:language_interface'],
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block', $edit);
|
||||
|
||||
// Check that we have the language in config after saving the setting.
|
||||
|
@ -96,7 +96,7 @@ class BlockLanguageTest extends WebTestBase {
|
|||
$this->assertEqual('fr', $visibility['language']['langcodes']['fr'], 'Language is set in the block configuration.');
|
||||
|
||||
// Delete the language.
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/fr', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/fr', [], t('Delete'));
|
||||
|
||||
// Check that the language is no longer stored in the configuration after
|
||||
// it is deleted.
|
|
@ -1,48 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the block_theme_suggestions_block() function.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockTemplateSuggestionsTest extends WebTestBase {
|
||||
class BlockTemplateSuggestionsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
/**
|
||||
* Tests template suggestions from block_theme_suggestions_block().
|
||||
*/
|
||||
function testBlockThemeHookSuggestions() {
|
||||
public function testBlockThemeHookSuggestions() {
|
||||
// Define a block with a derivative to be preprocessed, which includes both
|
||||
// an underscore (not transformed) and a hyphen (transformed to underscore),
|
||||
// and generates possibilities for each level of derivative.
|
||||
// @todo Clarify this comment.
|
||||
$block = Block::create(array(
|
||||
$block = Block::create([
|
||||
'plugin' => 'system_menu_block:admin',
|
||||
'region' => 'footer',
|
||||
'id' => 'machinename',
|
||||
));
|
||||
]);
|
||||
|
||||
$variables = array();
|
||||
$variables = [];
|
||||
$plugin = $block->getPlugin();
|
||||
$variables['elements']['#configuration'] = $plugin->getConfiguration();
|
||||
$variables['elements']['#plugin_id'] = $plugin->getPluginId();
|
||||
$variables['elements']['#id'] = $block->id();
|
||||
$variables['elements']['#base_plugin_id'] = $plugin->getBaseId();
|
||||
$variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId();
|
||||
$variables['elements']['content'] = array();
|
||||
$variables['elements']['content'] = [];
|
||||
$suggestions = block_theme_suggestions_block($variables);
|
||||
$this->assertEqual($suggestions, array('block__system', 'block__system_menu_block', 'block__system_menu_block__admin', 'block__machinename'));
|
||||
$this->assertEqual($suggestions, ['block__system', 'block__system_menu_block', 'block__system_menu_block__admin', 'block__machinename']);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block\Tests;
|
||||
namespace Drupal\Tests\block\Functional;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the new default theme gets blocks.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class NewDefaultThemeBlocksTest extends WebTestBase {
|
||||
class NewDefaultThemeBlocksTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
/**
|
||||
* Check the enabled Bartik blocks are correctly copied over.
|
||||
*/
|
||||
function testNewDefaultThemeBlocks() {
|
||||
public function testNewDefaultThemeBlocks() {
|
||||
$default_theme = $this->config('system.theme')->get('default');
|
||||
|
||||
// Add two instances of the user login block.
|
||||
$this->drupalPlaceBlock('user_login_block', array(
|
||||
$this->drupalPlaceBlock('user_login_block', [
|
||||
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
||||
));
|
||||
$this->drupalPlaceBlock('user_login_block', array(
|
||||
]);
|
||||
$this->drupalPlaceBlock('user_login_block', [
|
||||
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
||||
));
|
||||
]);
|
||||
|
||||
// Add an instance of a different block.
|
||||
$this->drupalPlaceBlock('system_powered_by_block', array(
|
||||
$this->drupalPlaceBlock('system_powered_by_block', [
|
||||
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
||||
));
|
||||
]);
|
||||
|
||||
// Install a different theme.
|
||||
$new_theme = 'bartik';
|
||||
$this->assertFalse($new_theme == $default_theme, 'The new theme is different from the previous default theme.');
|
||||
\Drupal::service('theme_handler')->install(array($new_theme));
|
||||
\Drupal::service('theme_handler')->install([$new_theme]);
|
||||
$this->config('system.theme')
|
||||
->set('default', $new_theme)
|
||||
->save();
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
|
||||
$block_storage = $this->container->get('entity_type.manager')->getStorage('block');
|
||||
|
||||
// Ensure that the new theme has all the blocks as the previous default.
|
||||
$default_block_names = $this->container->get('entity.query')->get('block')
|
||||
$default_block_names = $block_storage->getQuery()
|
||||
->condition('theme', $default_theme)
|
||||
->execute();
|
||||
$new_blocks = $this->container->get('entity.query')->get('block')
|
||||
$new_blocks = $block_storage->getQuery()
|
||||
->condition('theme', $new_theme)
|
||||
->execute();
|
||||
$this->assertTrue(count($default_block_names) == count($new_blocks), 'The new default theme has the same number of blocks as the previous theme.');
|
||||
|
@ -64,7 +67,7 @@ class NewDefaultThemeBlocksTest extends WebTestBase {
|
|||
// Install a hidden base theme and ensure blocks are not copied.
|
||||
$base_theme = 'test_basetheme';
|
||||
\Drupal::service('theme_handler')->install([$base_theme]);
|
||||
$new_blocks = $this->container->get('entity.query')->get('block')
|
||||
$new_blocks = $block_storage->getQuery()
|
||||
->condition('theme', $base_theme)
|
||||
->execute();
|
||||
$this->assertTrue(empty($new_blocks), 'Installing a hidden base theme does not copy blocks from the default theme.');
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\block\Kernel;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array(
|
||||
public static $modules = [
|
||||
'block',
|
||||
'aggregator',
|
||||
'book',
|
||||
|
@ -32,7 +32,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
|
|||
'taxonomy',
|
||||
'user',
|
||||
'text',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The typed config manager.
|
||||
|
@ -59,7 +59,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
|
|||
$this->installEntitySchema('block_content');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installSchema('book', array('book'));
|
||||
$this->installSchema('book', ['book']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,20 +68,20 @@ class BlockConfigSchemaTest extends KernelTestBase {
|
|||
public function testBlockConfigSchema() {
|
||||
foreach ($this->blockManager->getDefinitions() as $block_id => $definition) {
|
||||
$id = strtolower($this->randomMachineName());
|
||||
$block = Block::create(array(
|
||||
$block = Block::create([
|
||||
'id' => $id,
|
||||
'theme' => 'classy',
|
||||
'weight' => 00,
|
||||
'status' => TRUE,
|
||||
'region' => 'content',
|
||||
'plugin' => $block_id,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'label' => $this->randomMachineName(),
|
||||
'provider' => 'system',
|
||||
'label_display' => FALSE,
|
||||
),
|
||||
'visibility' => array(),
|
||||
));
|
||||
],
|
||||
'visibility' => [],
|
||||
]);
|
||||
$block->save();
|
||||
|
||||
$config = $this->config("block.block.$id");
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\block\Kernel;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\block\BlockInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ use Drupal\KernelTests\KernelTestBase;
|
|||
*/
|
||||
class BlockInterfaceTest extends KernelTestBase {
|
||||
|
||||
public static $modules = array('system', 'block', 'block_test', 'user');
|
||||
public static $modules = ['system', 'block', 'block_test', 'user'];
|
||||
|
||||
/**
|
||||
* Test configuration and subsequent form() and build() method calls.
|
||||
|
@ -31,16 +31,16 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
*/
|
||||
public function testBlockInterface() {
|
||||
$manager = $this->container->get('plugin.manager.block');
|
||||
$configuration = array(
|
||||
$configuration = [
|
||||
'label' => 'Custom Display Message',
|
||||
);
|
||||
$expected_configuration = array(
|
||||
];
|
||||
$expected_configuration = [
|
||||
'id' => 'test_block_instantiation',
|
||||
'label' => 'Custom Display Message',
|
||||
'provider' => 'block_test',
|
||||
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
'label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
|
||||
'display_message' => 'no message set',
|
||||
);
|
||||
];
|
||||
// Initial configuration of the block at construction time.
|
||||
/** @var $display_block \Drupal\Core\Block\BlockPluginInterface */
|
||||
$display_block = $manager->createInstance('test_block_instantiation', $configuration);
|
||||
|
@ -52,46 +52,46 @@ class BlockInterfaceTest extends KernelTestBase {
|
|||
$this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block configuration was updated correctly.');
|
||||
$definition = $display_block->getPluginDefinition();
|
||||
|
||||
$expected_form = array(
|
||||
'provider' => array(
|
||||
$expected_form = [
|
||||
'provider' => [
|
||||
'#type' => 'value',
|
||||
'#value' => 'block_test',
|
||||
),
|
||||
'admin_label' => array(
|
||||
],
|
||||
'admin_label' => [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Block description'),
|
||||
'#plain_text' => $definition['admin_label'],
|
||||
),
|
||||
'label' => array(
|
||||
],
|
||||
'label' => [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Title',
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => 'Custom Display Message',
|
||||
'#required' => TRUE,
|
||||
),
|
||||
'label_display' => array(
|
||||
],
|
||||
'label_display' => [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Display title',
|
||||
'#default_value' => TRUE,
|
||||
'#return_value' => 'visible',
|
||||
),
|
||||
'context_mapping' => array(),
|
||||
'display_message' => array(
|
||||
],
|
||||
'context_mapping' => [],
|
||||
'display_message' => [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Display message'),
|
||||
'#default_value' => 'My custom display message.',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$form_state = new FormState();
|
||||
// Ensure there are no form elements that do not belong to the plugin.
|
||||
$actual_form = $display_block->buildConfigurationForm(array(), $form_state);
|
||||
$actual_form = $display_block->buildConfigurationForm([], $form_state);
|
||||
// Remove the visibility sections, as that just tests condition plugins.
|
||||
unset($actual_form['visibility'], $actual_form['visibility_tabs']);
|
||||
$this->assertIdentical($this->castSafeStrings($actual_form), $this->castSafeStrings($expected_form), 'Only the expected form elements were present.');
|
||||
|
||||
$expected_build = array(
|
||||
$expected_build = [
|
||||
'#children' => 'My custom display message.',
|
||||
);
|
||||
];
|
||||
// Ensure the build array is proper.
|
||||
$this->assertIdentical($display_block->build(), $expected_build, 'The plugin returned the appropriate build array.');
|
||||
|
||||
|
|
103
web/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
Normal file
103
web/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block\Kernel;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\simpletest\BlockCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests block_rebuild().
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockRebuildTest extends KernelTestBase {
|
||||
|
||||
use BlockCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->container->get('theme_installer')->install(['stable', 'classy']);
|
||||
$this->container->get('config.factory')->getEditable('system.theme')->set('default', 'classy')->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
// @todo Once block_rebuild() is refactored to auto-loadable code, remove
|
||||
// this require statement.
|
||||
require_once static::getDrupalRoot() . '/core/modules/block/block.module';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::block_rebuild
|
||||
*/
|
||||
public function testRebuildNoBlocks() {
|
||||
block_rebuild();
|
||||
$messages = drupal_get_messages();
|
||||
$this->assertEquals([], $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::block_rebuild
|
||||
*/
|
||||
public function testRebuildNoInvalidBlocks() {
|
||||
$this->placeBlock('system_powered_by_block', ['region' => 'content']);
|
||||
|
||||
block_rebuild();
|
||||
$messages = drupal_get_messages();
|
||||
$this->assertEquals([], $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::block_rebuild
|
||||
*/
|
||||
public function testRebuildInvalidBlocks() {
|
||||
$this->placeBlock('system_powered_by_block', ['region' => 'content']);
|
||||
$block1 = $this->placeBlock('system_powered_by_block');
|
||||
$block2 = $this->placeBlock('system_powered_by_block');
|
||||
$block2->disable()->save();
|
||||
// Use the config API directly to bypass Block::preSave().
|
||||
\Drupal::configFactory()->getEditable('block.block.' . $block1->id())->set('region', 'INVALID')->save();
|
||||
\Drupal::configFactory()->getEditable('block.block.' . $block2->id())->set('region', 'INVALID')->save();
|
||||
|
||||
// Reload block entities.
|
||||
$block1 = Block::load($block1->id());
|
||||
$block2 = Block::load($block2->id());
|
||||
|
||||
$this->assertSame('INVALID', $block1->getRegion());
|
||||
$this->assertTrue($block1->status());
|
||||
$this->assertSame('INVALID', $block2->getRegion());
|
||||
$this->assertFalse($block2->status());
|
||||
|
||||
block_rebuild();
|
||||
|
||||
// Reload block entities.
|
||||
$block1 = Block::load($block1->id());
|
||||
$block2 = Block::load($block2->id());
|
||||
|
||||
$messages = drupal_get_messages();
|
||||
$expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block1->id(), '%region' => 'INVALID'])]];
|
||||
$this->assertEquals($expected, $messages);
|
||||
|
||||
$default_region = system_default_region('classy');
|
||||
$this->assertSame($default_region, $block1->getRegion());
|
||||
$this->assertFalse($block1->status());
|
||||
$this->assertSame($default_region, $block2->getRegion());
|
||||
$this->assertFalse($block2->status());
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Drupal\Tests\block\Kernel;
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\block_test\Plugin\Block\TestHtmlBlock;
|
||||
use Drupal\Component\Plugin\Exception\PluginException;
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\block\BlockInterface;
|
||||
|
||||
/**
|
||||
* Tests the storage of blocks.
|
||||
|
@ -21,7 +21,7 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test', 'system');
|
||||
public static $modules = ['block', 'block_test', 'system'];
|
||||
|
||||
/**
|
||||
* The block storage.
|
||||
|
@ -34,6 +34,8 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
parent::setUp();
|
||||
|
||||
$this->controller = $this->container->get('entity_type.manager')->getStorage('block');
|
||||
|
||||
$this->container->get('theme_installer')->install(['stark']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +56,7 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
protected function createTests() {
|
||||
// Attempt to create a block without a plugin.
|
||||
try {
|
||||
$entity = $this->controller->create(array());
|
||||
$entity = $this->controller->create([]);
|
||||
$entity->getPlugin();
|
||||
$this->fail('A block without a plugin was created with no exception thrown.');
|
||||
}
|
||||
|
@ -63,11 +65,12 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
}
|
||||
|
||||
// Create a block with only required values.
|
||||
$entity = $this->controller->create(array(
|
||||
$entity = $this->controller->create([
|
||||
'id' => 'test_block',
|
||||
'theme' => 'stark',
|
||||
'region' => 'content',
|
||||
'plugin' => 'test_html',
|
||||
));
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
$this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.');
|
||||
|
@ -78,24 +81,24 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
unset($actual_properties['uuid']);
|
||||
|
||||
// Ensure that default values are filled in.
|
||||
$expected_properties = array(
|
||||
$expected_properties = [
|
||||
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
|
||||
'status' => TRUE,
|
||||
'dependencies' => array('module' => array('block_test'), 'theme' => array('stark')),
|
||||
'dependencies' => ['module' => ['block_test'], 'theme' => ['stark']],
|
||||
'id' => 'test_block',
|
||||
'theme' => 'stark',
|
||||
'region' => '-1',
|
||||
'region' => 'content',
|
||||
'weight' => NULL,
|
||||
'provider' => NULL,
|
||||
'plugin' => 'test_html',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'id' => 'test_html',
|
||||
'label' => '',
|
||||
'provider' => 'block_test',
|
||||
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
),
|
||||
'visibility' => array(),
|
||||
);
|
||||
'label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
|
||||
],
|
||||
'visibility' => [],
|
||||
];
|
||||
|
||||
$this->assertIdentical($actual_properties, $expected_properties);
|
||||
|
||||
|
@ -111,7 +114,7 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
$this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.');
|
||||
|
||||
// Verify several properties of the block.
|
||||
$this->assertEqual($entity->getRegion(), '-1');
|
||||
$this->assertSame('content', $entity->getRegion());
|
||||
$this->assertTrue($entity->status());
|
||||
$this->assertEqual($entity->getTheme(), 'stark');
|
||||
$this->assertTrue($entity->uuid());
|
||||
|
@ -145,7 +148,7 @@ class BlockStorageUnitTest extends KernelTestBase {
|
|||
$this->assertTrue(empty($entities), 'There are no blocks initially.');
|
||||
|
||||
// Install the block_test.module, so that its default config is installed.
|
||||
$this->installConfig(array('block_test'));
|
||||
$this->installConfig(['block_test']);
|
||||
|
||||
$entities = $this->controller->loadMultiple();
|
||||
$entity = reset($entities);
|
||||
|
|
|
@ -20,7 +20,7 @@ class BlockViewBuilderTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'block_test', 'system', 'user');
|
||||
public static $modules = ['block', 'block_test', 'system', 'user'];
|
||||
|
||||
/**
|
||||
* The block being tested.
|
||||
|
@ -56,11 +56,11 @@ class BlockViewBuilderTest extends KernelTestBase {
|
|||
\Drupal::state()->set('block_test.content', 'Llamas > unicorns!');
|
||||
|
||||
// Create a block with only required values.
|
||||
$this->block = $this->controller->create(array(
|
||||
$this->block = $this->controller->create([
|
||||
'id' => 'test_block',
|
||||
'theme' => 'stark',
|
||||
'plugin' => 'test_cache',
|
||||
));
|
||||
]);
|
||||
$this->block->save();
|
||||
|
||||
$this->container->get('cache.render')->deleteAll();
|
||||
|
@ -74,17 +74,17 @@ class BlockViewBuilderTest extends KernelTestBase {
|
|||
public function testBasicRendering() {
|
||||
\Drupal::state()->set('block_test.content', '');
|
||||
|
||||
$entity = $this->controller->create(array(
|
||||
$entity = $this->controller->create([
|
||||
'id' => 'test_block1',
|
||||
'theme' => 'stark',
|
||||
'plugin' => 'test_html',
|
||||
));
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
// Test the rendering of a block.
|
||||
$entity = Block::load('test_block1');
|
||||
$output = entity_view($entity, 'block');
|
||||
$expected = array();
|
||||
$expected = [];
|
||||
$expected[] = '<div id="block-test-block1">';
|
||||
$expected[] = ' ';
|
||||
$expected[] = ' ';
|
||||
|
@ -98,17 +98,17 @@ class BlockViewBuilderTest extends KernelTestBase {
|
|||
Html::resetSeenIds();
|
||||
|
||||
// Test the rendering of a block with a given title.
|
||||
$entity = $this->controller->create(array(
|
||||
$entity = $this->controller->create([
|
||||
'id' => 'test_block2',
|
||||
'theme' => 'stark',
|
||||
'plugin' => 'test_html',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'label' => 'Powered by Bananas',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
$output = entity_view($entity, 'block');
|
||||
$expected = array();
|
||||
$expected = [];
|
||||
$expected[] = '<div id="block-test-block2">';
|
||||
$expected[] = ' ';
|
||||
$expected[] = ' <h2>Powered by Bananas</h2>';
|
||||
|
@ -128,11 +128,11 @@ class BlockViewBuilderTest extends KernelTestBase {
|
|||
$this->verifyRenderCacheHandling();
|
||||
|
||||
// Create an empty block.
|
||||
$this->block = $this->controller->create(array(
|
||||
$this->block = $this->controller->create([
|
||||
'id' => 'test_block',
|
||||
'theme' => 'stark',
|
||||
'plugin' => 'test_cache',
|
||||
));
|
||||
]);
|
||||
$this->block->save();
|
||||
\Drupal::state()->set('block_test.content', NULL);
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Install the themes used for this test.
|
||||
$this->container->get('theme_installer')->install(['bartik', 'seven', 'test_theme']);
|
||||
|
||||
$this->installConfig(['block_content']);
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
|
@ -37,9 +41,6 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
$config->set('admin', 'seven');
|
||||
$config->save();
|
||||
|
||||
// Install one of D8's test themes.
|
||||
\Drupal::service('theme_handler')->install(['test_theme']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'd6_filter_format',
|
||||
'block_content_type',
|
||||
|
@ -70,7 +71,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
* @param string $label_display
|
||||
* The block label display setting.
|
||||
* @param bool $status
|
||||
* (optional) Whether the block is expected to be enabled.
|
||||
* Whether the block is expected to be enabled or disabled.
|
||||
*/
|
||||
public function assertEntity($id, $visibility, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
|
||||
$block = Block::load($id);
|
||||
|
@ -141,10 +142,9 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
|
|||
$visibility['request_path']['id'] = 'request_path';
|
||||
$visibility['request_path']['negate'] = FALSE;
|
||||
$visibility['request_path']['pages'] = '/node';
|
||||
// bluemarine does not exist in Drupal 8 and the d6_block migration defines
|
||||
// no mapping for its regions, so this block should have been defaulted
|
||||
// to the 'content' region.
|
||||
$this->assertEntity('block_1', $visibility, 'content', 'bluemarine', -4, 'Another Static Block', 'visible');
|
||||
// We expect this block to be disabled because '' is not a valid region,
|
||||
// and block_rebuild() will disable any block in an invalid region.
|
||||
$this->assertEntity('block_1', $visibility, '', 'bluemarine', -4, 'Another Static Block', 'visible', FALSE);
|
||||
|
||||
$visibility = [];
|
||||
$this->assertEntity('block_2', $visibility, 'right', 'test_theme', -7, '', '0');
|
||||
|
|
|
@ -33,6 +33,10 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Install the themes used for this test.
|
||||
$this->container->get('theme_installer')->install(['bartik', 'seven']);
|
||||
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
|
@ -42,9 +46,6 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
$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',
|
||||
|
@ -78,7 +79,7 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
|
|||
* @param string $label_display
|
||||
* The block label display setting.
|
||||
* @param bool $status
|
||||
* (optional) Whether the block is expected to be enabled.
|
||||
* Whether the block is expected to be enabled or disabled.
|
||||
*/
|
||||
public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
|
||||
$block = Block::load($id);
|
||||
|
|
|
@ -69,20 +69,20 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
|
|||
* @covers ::calculateDependencies
|
||||
*/
|
||||
public function testCalculateDependencies() {
|
||||
$values = array('theme' => 'stark');
|
||||
$values = ['theme' => 'stark'];
|
||||
// Mock the entity under test so that we can mock getPluginCollections().
|
||||
$entity = $this->getMockBuilder('\Drupal\block\Entity\Block')
|
||||
->setConstructorArgs(array($values, $this->entityTypeId))
|
||||
->setMethods(array('getPluginCollections'))
|
||||
->setConstructorArgs([$values, $this->entityTypeId])
|
||||
->setMethods(['getPluginCollections'])
|
||||
->getMock();
|
||||
// Create a configurable plugin that would add a dependency.
|
||||
$instance_id = $this->randomMachineName();
|
||||
$instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test'));
|
||||
$instance = new TestConfigurablePlugin([], $instance_id, ['provider' => 'test']);
|
||||
|
||||
// Create a plugin collection to contain the instance.
|
||||
$plugin_collection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('get'))
|
||||
->setMethods(['get'])
|
||||
->getMock();
|
||||
$plugin_collection->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
|
@ -93,7 +93,7 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
|
|||
// Return the mocked plugin collection.
|
||||
$entity->expects($this->once())
|
||||
->method('getPluginCollections')
|
||||
->will($this->returnValue(array($plugin_collection)));
|
||||
->will($this->returnValue([$plugin_collection]));
|
||||
|
||||
$dependencies = $entity->calculateDependencies()->getDependencies();
|
||||
$this->assertContains('test', $dependencies['module']);
|
||||
|
|
|
@ -88,7 +88,7 @@ class BlockFormTest extends UnitTestCase {
|
|||
* @see \Drupal\block\BlockForm::getUniqueMachineName()
|
||||
*/
|
||||
public function testGetUniqueMachineName() {
|
||||
$blocks = array();
|
||||
$blocks = [];
|
||||
|
||||
$blocks['test'] = $this->getBlockMockWithMachineName('test');
|
||||
$blocks['other_test'] = $this->getBlockMockWithMachineName('other_test');
|
||||
|
@ -102,7 +102,7 @@ class BlockFormTest extends UnitTestCase {
|
|||
|
||||
$query->expects($this->exactly(5))
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test', 'other_test', 'other_test_1', 'other_test_2')));
|
||||
->will($this->returnValue(['test', 'other_test', 'other_test_1', 'other_test_2']));
|
||||
|
||||
$this->storage->expects($this->exactly(5))
|
||||
->method('getQuery')
|
||||
|
|
|
@ -116,25 +116,25 @@ class BlockRepositoryTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
public function providerBlocksConfig() {
|
||||
$blocks_config = array(
|
||||
'block1' => array(
|
||||
$blocks_config = [
|
||||
'block1' => [
|
||||
AccessResult::allowed(), 'top', 0
|
||||
),
|
||||
],
|
||||
// Test a block without access.
|
||||
'block2' => array(
|
||||
'block2' => [
|
||||
AccessResult::forbidden(), 'bottom', 0
|
||||
),
|
||||
],
|
||||
// Test some blocks in the same region with specific weight.
|
||||
'block4' => array(
|
||||
'block4' => [
|
||||
AccessResult::allowed(), 'bottom', 5
|
||||
),
|
||||
'block3' => array(
|
||||
],
|
||||
'block3' => [
|
||||
AccessResult::allowed(), 'bottom', 5
|
||||
),
|
||||
'block5' => array(
|
||||
],
|
||||
'block5' => [
|
||||
AccessResult::allowed(), 'bottom', -5
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$test_cases = [];
|
||||
$test_cases[] = [$blocks_config,
|
||||
|
|
|
@ -24,7 +24,7 @@ class CategoryAutocompleteTest extends UnitTestCase {
|
|||
$block_manager = $this->getMock('Drupal\Core\Block\BlockManagerInterface');
|
||||
$block_manager->expects($this->any())
|
||||
->method('getCategories')
|
||||
->will($this->returnValue(array('Comment', 'Node', 'None & Such', 'User')));
|
||||
->will($this->returnValue(['Comment', 'Node', 'None & Such', 'User']));
|
||||
|
||||
$this->autocompleteController = new CategoryAutocompleteController($block_manager);
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ class CategoryAutocompleteTest extends UnitTestCase {
|
|||
*/
|
||||
public function testAutocompleteSuggestions($string, $suggestions) {
|
||||
$suggestions = array_map(function ($suggestion) {
|
||||
return array('value' => $suggestion, 'label' => Html::escape($suggestion));
|
||||
return ['value' => $suggestion, 'label' => Html::escape($suggestion)];
|
||||
}, $suggestions);
|
||||
$result = $this->autocompleteController->autocomplete(new Request(array('q' => $string)));
|
||||
$result = $this->autocompleteController->autocomplete(new Request(['q' => $string]));
|
||||
$this->assertSame($suggestions, json_decode($result->getContent(), TRUE));
|
||||
}
|
||||
|
||||
|
@ -55,30 +55,30 @@ class CategoryAutocompleteTest extends UnitTestCase {
|
|||
* @return array
|
||||
*/
|
||||
public function providerTestAutocompleteSuggestions() {
|
||||
$test_parameters = array();
|
||||
$test_parameters[] = array(
|
||||
$test_parameters = [];
|
||||
$test_parameters[] = [
|
||||
'string' => 'Com',
|
||||
'suggestions' => array(
|
||||
'suggestions' => [
|
||||
'Comment',
|
||||
),
|
||||
);
|
||||
$test_parameters[] = array(
|
||||
],
|
||||
];
|
||||
$test_parameters[] = [
|
||||
'string' => 'No',
|
||||
'suggestions' => array(
|
||||
'suggestions' => [
|
||||
'Node',
|
||||
'None & Such',
|
||||
),
|
||||
);
|
||||
$test_parameters[] = array(
|
||||
],
|
||||
];
|
||||
$test_parameters[] = [
|
||||
'string' => 'us',
|
||||
'suggestions' => array(
|
||||
'suggestions' => [
|
||||
'User',
|
||||
),
|
||||
);
|
||||
$test_parameters[] = array(
|
||||
],
|
||||
];
|
||||
$test_parameters[] = [
|
||||
'string' => 'Banana',
|
||||
'suggestions' => array(),
|
||||
);
|
||||
'suggestions' => [],
|
||||
];
|
||||
return $test_parameters;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,33 +13,33 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||
class BlockLocalTasksTest extends LocalTaskIntegrationTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
$this->directoryList = array('block' => 'core/modules/block');
|
||||
$this->directoryList = ['block' => 'core/modules/block'];
|
||||
parent::setUp();
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(array('system.theme' => array(
|
||||
$config_factory = $this->getConfigFactoryStub(['system.theme' => [
|
||||
'default' => 'test_c',
|
||||
)));
|
||||
]]);
|
||||
|
||||
$themes = array();
|
||||
$themes['test_a'] = (object) array(
|
||||
$themes = [];
|
||||
$themes['test_a'] = (object) [
|
||||
'status' => 1,
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'test_a',
|
||||
'hidden' => TRUE,
|
||||
),
|
||||
);
|
||||
$themes['test_b'] = (object) array(
|
||||
],
|
||||
];
|
||||
$themes['test_b'] = (object) [
|
||||
'status' => 1,
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'test_b',
|
||||
),
|
||||
);
|
||||
$themes['test_c'] = (object) array(
|
||||
],
|
||||
];
|
||||
$themes['test_c'] = (object) [
|
||||
'status' => 1,
|
||||
'info' => array(
|
||||
'info' => [
|
||||
'name' => 'test_c',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$theme_handler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface');
|
||||
$theme_handler->expects($this->any())
|
||||
->method('listInfo')
|
||||
|
@ -63,7 +63,7 @@ class BlockLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* Tests the admin edit local task.
|
||||
*/
|
||||
public function testBlockAdminLocalTasks() {
|
||||
$this->assertLocalTasks('entity.block.edit_form', array(array('entity.block.edit_form')));
|
||||
$this->assertLocalTasks('entity.block.edit_form', [['entity.block.edit_form']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,10 +79,10 @@ class BlockLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
* Provides a list of routes to test.
|
||||
*/
|
||||
public function providerTestBlockAdminDisplay() {
|
||||
return array(
|
||||
array('block.admin_display', array(array('block.admin_display'), array('block.admin_display_theme:test_b', 'block.admin_display_theme:test_c'))),
|
||||
array('block.admin_display_theme', array(array('block.admin_display'), array('block.admin_display_theme:test_b', 'block.admin_display_theme:test_c'))),
|
||||
);
|
||||
return [
|
||||
['block.admin_display', [['block.admin_display'], ['block.admin_display_theme:test_b', 'block.admin_display_theme:test_c']]],
|
||||
['block.admin_display_theme', [['block.admin_display'], ['block.admin_display_theme:test_b', 'block.admin_display_theme:test_c']]],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class BlockPageVariantTest extends UnitTestCase {
|
|||
* @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant|\PHPUnit_Framework_MockObject_MockObject
|
||||
* A mocked display variant plugin.
|
||||
*/
|
||||
public function setUpDisplayVariant($configuration = array(), $definition = array()) {
|
||||
public function setUpDisplayVariant($configuration = [], $definition = []) {
|
||||
|
||||
$container = new Container();
|
||||
$cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager')
|
||||
|
@ -60,37 +60,37 @@ class BlockPageVariantTest extends UnitTestCase {
|
|||
$this->blockViewBuilder = $this->getMock('Drupal\Core\Entity\EntityViewBuilderInterface');
|
||||
|
||||
return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\BlockPageVariant')
|
||||
->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']))
|
||||
->setMethods(array('getRegionNames'))
|
||||
->setConstructorArgs([$configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']])
|
||||
->setMethods(['getRegionNames'])
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function providerBuild() {
|
||||
$blocks_config = array(
|
||||
'block1' => array(
|
||||
$blocks_config = [
|
||||
'block1' => [
|
||||
// region, is main content block, is messages block, is title block
|
||||
'top', FALSE, FALSE, FALSE,
|
||||
),
|
||||
],
|
||||
// Test multiple blocks in the same region.
|
||||
'block2' => array(
|
||||
'block2' => [
|
||||
'bottom', FALSE, FALSE, FALSE,
|
||||
),
|
||||
'block3' => array(
|
||||
],
|
||||
'block3' => [
|
||||
'bottom', FALSE, FALSE, FALSE,
|
||||
),
|
||||
],
|
||||
// Test a block implementing MainContentBlockPluginInterface.
|
||||
'block4' => array(
|
||||
'block4' => [
|
||||
'center', TRUE, FALSE, FALSE,
|
||||
),
|
||||
],
|
||||
// Test a block implementing MessagesBlockPluginInterface.
|
||||
'block5' => array(
|
||||
'block5' => [
|
||||
'center', FALSE, TRUE, FALSE,
|
||||
),
|
||||
],
|
||||
// Test a block implementing TitleBlockPluginInterface.
|
||||
'block6' => array(
|
||||
'block6' => [
|
||||
'center', FALSE, FALSE, TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$test_cases = [];
|
||||
$test_cases[] = [$blocks_config, 6,
|
||||
|
@ -219,7 +219,7 @@ class BlockPageVariantTest extends UnitTestCase {
|
|||
}
|
||||
$this->blockViewBuilder->expects($this->exactly($visible_block_count))
|
||||
->method('view')
|
||||
->will($this->returnValue(array()));
|
||||
->will($this->returnValue([]));
|
||||
$this->blockRepository->expects($this->once())
|
||||
->method('getVisibleBlocksPerRegion')
|
||||
->willReturnCallback(function (&$cacheable_metadata) use ($blocks) {
|
||||
|
|
Reference in a new issue