diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml
index c695934..fd1e6a2 100644
--- a/core/config/schema/core.data_types.schema.yml
+++ b/core/config/schema/core.data_types.schema.yml
@@ -279,12 +279,6 @@ block_settings:
view_mode:
type: string
label: 'View mode'
- visibility:
- type: sequence
- label: 'Visibility Conditions'
- sequence:
- - type: condition.plugin.[id]
- label: 'Visibility Condition'
provider:
type: string
label: 'Provider'
diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php
index 2be3670..d4213b4 100644
--- a/core/lib/Drupal/Core/Block/BlockBase.php
+++ b/core/lib/Drupal/Core/Block/BlockBase.php
@@ -8,13 +8,8 @@
namespace Drupal\Core\Block;
use Drupal\block\BlockInterface;
-use Drupal\block\Event\BlockConditionContextEvent;
-use Drupal\block\Event\BlockEvents;
-use Drupal\Component\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Condition\ConditionAccessResolverTrait;
-use Drupal\Core\Condition\ConditionPluginCollection;
-use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContextAwarePluginBase;
use Drupal\Component\Utility\Unicode;
@@ -35,22 +30,6 @@
*/
abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginInterface {
- use ConditionAccessResolverTrait;
-
- /**
- * The condition plugin collection.
- *
- * @var \Drupal\Core\Condition\ConditionPluginCollection
- */
- protected $conditionCollection;
-
- /**
- * The condition plugin manager.
- *
- * @var \Drupal\Core\Executable\ExecutableManagerInterface
- */
- protected $conditionPluginManager;
-
/**
* The transliteration service.
*
@@ -84,9 +63,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
* {@inheritdoc}
*/
public function getConfiguration() {
- return array(
- 'visibility' => $this->getVisibilityConditions()->getConfiguration(),
- ) + $this->configuration;
+ return $this->configuration;
}
/**
@@ -107,13 +84,6 @@ public function setConfiguration(array $configuration) {
* An associative array with the default configuration.
*/
protected function baseConfigurationDefaults() {
- // @todo Allow list of conditions to be configured in
- // https://drupal.org/node/2284687.
- $visibility = array_map(function ($definition) {
- return array('id' => $definition['id']);
- }, $this->conditionPluginManager()->getDefinitions());
- unset($visibility['current_theme']);
-
return array(
'id' => $this->getPluginId(),
'label' => '',
@@ -123,7 +93,6 @@ protected function baseConfigurationDefaults() {
'max_age' => 0,
'contexts' => array(),
),
- 'visibility' => $visibility,
);
}
@@ -152,25 +121,8 @@ public function calculateDependencies() {
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
- // @todo Add in a context mapping until the UI supports configuring them,
- // see https://drupal.org/node/2284687.
- $mappings['user_role']['current_user'] = 'user';
-
- $conditions = $this->getVisibilityConditions();
- $contexts = $this->getConditionContexts();
- foreach ($conditions as $condition_id => $condition) {
- if ($condition instanceof ContextAwarePluginInterface) {
- if (!isset($mappings[$condition_id])) {
- $mappings[$condition_id] = array();
- }
- $this->contextHandler()->applyContextMapping($condition, $contexts, $mappings[$condition_id]);
- }
- }
- // This should not be hardcoded to an uncacheable access check result, but
- // in order to fix that, we need condition plugins to return cache contexts,
- // otherwise it will be impossible to determine by which cache contexts the
// result should be varied.
- if ($this->resolveConditions($conditions, 'and', $contexts, $mappings) !== FALSE && $this->blockAccess($account)) {
+ if ($this->blockAccess($account)) {
$access = AccessResult::allowed();
}
else {
@@ -180,18 +132,6 @@ public function access(AccountInterface $account) {
}
/**
- * Gets the values for all defined contexts.
- *
- * @return \Drupal\Component\Plugin\Context\ContextInterface[]
- * An array of set contexts, keyed by context name.
- */
- protected function getConditionContexts() {
- $conditions = $this->getVisibilityConditions();
- $this->eventDispatcher()->dispatch(BlockEvents::CONDITION_CONTEXT, new BlockConditionContextEvent($conditions));
- return $conditions->getConditionContexts();
- }
-
- /**
* Indicates whether the block should be shown.
*
* @param \Drupal\Core\Session\AccountInterface $account
@@ -287,53 +227,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['cache']['contexts']['#description'] .= ' ' . t('This block is always varied by the following contexts: %required-context-list.', array('%required-context-list' => $required_context_list));
}
- $form['visibility_tabs'] = array(
- '#type' => 'vertical_tabs',
- '#title' => $this->t('Visibility'),
- '#parents' => array('visibility_tabs'),
- '#attached' => array(
- 'library' => array(
- 'block/drupal.block',
- ),
- ),
- );
- foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
- $condition_form = $condition->buildConfigurationForm(array(), $form_state);
- $condition_form['#type'] = 'details';
- $condition_form['#title'] = $condition->getPluginDefinition()['label'];
- $condition_form['#group'] = 'visibility_tabs';
- $form['visibility'][$condition_id] = $condition_form;
- }
-
- // @todo Determine if there is a better way to rename the conditions.
- if (isset($form['visibility']['node_type'])) {
- $form['visibility']['node_type']['#title'] = $this->t('Content types');
- $form['visibility']['node_type']['bundles']['#title'] = $this->t('Content types');
- $form['visibility']['node_type']['negate']['#type'] = 'value';
- $form['visibility']['node_type']['negate']['#title_display'] = 'invisible';
- $form['visibility']['node_type']['negate']['#value'] = $form['visibility']['node_type']['negate']['#default_value'];
- }
- if (isset($form['visibility']['user_role'])) {
- $form['visibility']['user_role']['#title'] = $this->t('Roles');
- unset($form['visibility']['user_role']['roles']['#description']);
- $form['visibility']['user_role']['negate']['#type'] = 'value';
- $form['visibility']['user_role']['negate']['#value'] = $form['visibility']['user_role']['negate']['#default_value'];
- }
- if (isset($form['visibility']['request_path'])) {
- $form['visibility']['request_path']['#title'] = $this->t('Pages');
- $form['visibility']['request_path']['negate']['#type'] = 'radios';
- $form['visibility']['request_path']['negate']['#title_display'] = 'invisible';
- $form['visibility']['request_path']['negate']['#default_value'] = (int) $form['visibility']['request_path']['negate']['#default_value'];
- $form['visibility']['request_path']['negate']['#options'] = array(
- $this->t('Show for the listed pages'),
- $this->t('Hide for the listed pages'),
- );
- }
- if (isset($form['visibility']['language'])) {
- $form['visibility']['language']['negate']['#type'] = 'value';
- $form['visibility']['language']['negate']['#value'] = $form['visibility']['language']['negate']['#default_value'];
- }
-
// Add plugin-specific settings for this block type.
$form += $this->blockForm($form, $form_state);
return $form;
@@ -362,15 +255,6 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
$contexts = $form_state->getValue(array('cache', 'contexts'));
$form_state->setValue(array('cache', 'contexts'), array_values(array_filter($contexts)));
- foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
- // Allow the condition to validate the form.
- $condition_values = (new FormState())
- ->setValues($form_state->getValue(['visibility', $condition_id]));
- $condition->validateConfigurationForm($form, $condition_values);
- // Update the original form values.
- $form_state->setValue(['visibility', $condition_id], $condition_values->getValues());
- }
-
$this->blockValidate($form, $form_state);
}
@@ -394,14 +278,6 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$this->configuration['label_display'] = $form_state->getValue('label_display');
$this->configuration['provider'] = $form_state->getValue('provider');
$this->configuration['cache'] = $form_state->getValue('cache');
- foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
- // Allow the condition to submit the form.
- $condition_values = (new FormState())
- ->setValues($form_state->getValue(['visibility', $condition_id]));
- $condition->submitConfigurationForm($form, $condition_values);
- // Update the original form values.
- $form_state->setValue(['visibility', $condition_id], $condition_values->getValues());
- }
$this->blockSubmit($form, $form_state);
}
}
@@ -503,61 +379,4 @@ public function isCacheable() {
return $max_age === Cache::PERMANENT || $max_age > 0;
}
- /**
- * {@inheritdoc}
- */
- public function getVisibilityConditions() {
- if (!isset($this->conditionCollection)) {
- $this->conditionCollection = new ConditionPluginCollection($this->conditionPluginManager(), $this->configuration['visibility']);
- }
- return $this->conditionCollection;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getVisibilityCondition($instance_id) {
- return $this->getVisibilityConditions()->get($instance_id);
- }
-
- /**
- * {@inheritdoc}
- */
- public function setVisibilityConfig($instance_id, array $configuration) {
- $this->getVisibilityConditions()->setInstanceConfiguration($instance_id, $configuration);
- return $this;
- }
-
- /**
- * Gets the condition plugin manager.
- *
- * @return \Drupal\Core\Executable\ExecutableManagerInterface
- * The condition plugin manager.
- */
- protected function conditionPluginManager() {
- if (!isset($this->conditionPluginManager)) {
- $this->conditionPluginManager = \Drupal::service('plugin.manager.condition');
- }
- return $this->conditionPluginManager;
- }
-
- /**
- * Wraps the event dispatcher.
- *
- * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
- * The event dispatcher.
- */
- protected function eventDispatcher() {
- return \Drupal::service('event_dispatcher');
- }
-
- /**
- * Wraps the context handler.
- *
- * @return \Drupal\Core\Plugin\Context\ContextHandlerInterface
- */
- protected function contextHandler() {
- return \Drupal::service('context.handler');
- }
-
}
diff --git a/core/lib/Drupal/Core/Block/BlockPluginInterface.php b/core/lib/Drupal/Core/Block/BlockPluginInterface.php
index 01f97ad..f63a955 100644
--- a/core/lib/Drupal/Core/Block/BlockPluginInterface.php
+++ b/core/lib/Drupal/Core/Block/BlockPluginInterface.php
@@ -7,7 +7,6 @@
namespace Drupal\Core\Block;
-use Drupal\Component\Plugin\Context\ContextInterface;
use Drupal\Component\Plugin\DerivativeInspectionInterface;
use Drupal\Core\Cache\CacheableInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
@@ -143,35 +142,4 @@ public function blockSubmit($form, FormStateInterface $form_state);
*/
public function getMachineNameSuggestion();
- /**
- * Gets conditions for this block.
- *
- * @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginCollection
- * An array or collection of configured condition plugins.
- */
- public function getVisibilityConditions();
-
- /**
- * Gets a visibility condition plugin instance.
- *
- * @param string $instance_id
- * The condition plugin instance ID.
- *
- * @return \Drupal\Core\Condition\ConditionInterface
- * A condition plugin.
- */
- public function getVisibilityCondition($instance_id);
-
- /**
- * Sets the visibility condition configuration.
- *
- * @param string $instance_id
- * The condition instance ID.
- * @param array $configuration
- * The condition configuration.
- *
- * @return $this
- */
- public function setVisibilityConfig($instance_id, array $configuration);
-
}
diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
index ed28d69..d6edb09 100644
--- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
@@ -26,8 +26,6 @@
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
-
- $this->setConfiguration($configuration);
}
/**
@@ -41,10 +39,13 @@ public function isNegated() {
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
+ $context_form = [];
+ $context_form['context_mapping']['#weight'] = -100;
+ $form += $this->getContextForm($context_form, $form_state);
$form['negate'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Negate the condition'),
- '#default_value' => $this->configuration['negate'],
+ '#default_value' => !empty($this->configuration['negate']) ? $this->configuration['negate'] : FALSE,
);
return $form;
}
@@ -59,6 +60,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+ $this->saveContextConfiguration($form, $form_state);
$this->configuration['negate'] = $form_state->getValue('negate');
}
diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php b/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php
deleted file mode 100644
index c2e532f..0000000
--- a/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php
+++ /dev/null
@@ -1,76 +0,0 @@
- $instance_config) {
- $default_config = array();
- $default_config['id'] = $instance_id;
- $default_config += $this->get($instance_id)->defaultConfiguration();
- if ($default_config === $instance_config) {
- unset($configuration[$instance_id]);
- }
- }
- return $configuration;
- }
-
- /**
- * Sets the condition context for a given name.
- *
- * @param string $name
- * The name of the context.
- * @param \Drupal\Component\Plugin\Context\ContextInterface $context
- * The context to add.
- *
- * @return $this
- */
- public function addContext($name, ContextInterface $context) {
- $this->conditionContexts[$name] = $context;
- return $this;
- }
-
- /**
- * Gets the values for all defined contexts.
- *
- * @return \Drupal\Component\Plugin\Context\ContextInterface[]
- * An array of set contexts, keyed by context name.
- */
- public function getConditionContexts() {
- return $this->conditionContexts;
- }
-
-}
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php
index 8063b2d..a866f2c 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php
@@ -8,6 +8,7 @@
namespace Drupal\Core\Plugin\Context;
use Drupal\Component\Utility\String;
+use Drupal\Core\Annotation\Translation;
use Drupal\Core\TypedData\TypedDataTrait;
/**
@@ -120,6 +121,9 @@ public function setDataType($data_type) {
* {@inheritdoc}
*/
public function getLabel() {
+ if ($this->label instanceof Translation) {
+ return (string) $this->label->get();
+ }
return $this->label;
}
diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
index 1fec193..7e65d2c 100644
--- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
+++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\ContextAwarePluginBase as ComponentContextAwarePluginBase;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
+use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\TypedData\TypedDataTrait;
@@ -49,4 +50,61 @@ public function setContext($name, ComponentContextInterface $context) {
parent::setContext($name, $context);
}
+ /**
+ * Return the form array for picking relevant context of this plugin.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return array
+ */
+ protected function getContextForm(array $form, FormStateInterface $form_state) {
+ /**
+ * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface $handler
+ */
+ $handler = \Drupal::service('context.handler');
+ $contexts = $form_state->get('context_mapping');
+ /**
+ * @var \Drupal\Component\Plugin\Context\ContextDefinitionInterface $context_definition
+ */
+ if ($this->getContextDefinitions()) {
+ foreach ($this->getContextDefinitions() as $name => $context_definition) {
+ $options = array();
+ $form['context_mapping']['#tree'] = TRUE;
+ foreach ($handler->getMatchingContexts($contexts, $context_definition) as $context_id => $context) {
+ $options[$context_id] = $context->getContextDefinition()->getLabel();
+ $form['context_mapping'][$name] = [
+ '#type' => 'value',
+ '#value' => $context_id,
+ ];
+ }
+ if (count($options) > 1) {
+ $form['context_mapping'][$name] = array(
+ '#title' => $context_definition->getLabel(),
+ '#type' => 'select',
+ '#required' => $context_definition->isRequired(),
+ '#options' => $options,
+ '#default_value' => !empty($this->configuration['context_mapping'][$name]) ? $this->configuration['context_mapping'][$name] : '',
+ );
+ }
+ }
+ }
+ return $form;
+ }
+
+ /**
+ * Extract context settings from form values and place them in configuration.
+ *
+ * @param array $form
+ * @param FormStateInterface $form_state
+ */
+ protected function saveContextConfiguration(array &$form, FormStateInterface $form_state) {
+ $contexts = $form_state->getValue('context_mapping');
+ if (!is_null($contexts)) {
+ $this->configuration['context_mapping'] = $contexts;
+ }
+ }
+
}
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 39e15ea..71616cd 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -322,7 +322,7 @@ function block_configurable_language_delete(ConfigurableLanguage $language) {
$visibility = $block->getVisibility();
if (isset($visibility['language']['langcodes'][$language->id()])) {
unset($visibility['language']['langcodes'][$language->id()]);
- $block->getPlugin()->setVisibilityConfig('language', $visibility['language']);
+ $block->setVisibilityConfig('language', $visibility['language']);
$block->save();
}
}
diff --git a/core/modules/block/config/schema/block.schema.yml b/core/modules/block/config/schema/block.schema.yml
index c142f89..1e6b823 100644
--- a/core/modules/block/config/schema/block.schema.yml
+++ b/core/modules/block/config/schema/block.schema.yml
@@ -24,6 +24,12 @@ block.block.*:
label: 'Plugin'
settings:
type: block.settings.[%parent.plugin]
+ visibility:
+ type: sequence
+ label: 'Visibility Conditions'
+ sequence:
+ - type: condition.plugin.[id]
+ label: 'Visibility Condition'
block.settings.*:
type: block_settings
diff --git a/core/modules/block/src/BlockAccessControlHandler.php b/core/modules/block/src/BlockAccessControlHandler.php
index 8bfa365..b1d1773 100644
--- a/core/modules/block/src/BlockAccessControlHandler.php
+++ b/core/modules/block/src/BlockAccessControlHandler.php
@@ -7,23 +7,65 @@
namespace Drupal\block;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
+use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Condition\ConditionAccessResolverTrait;
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\Session\AccountInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines the access control handler for the block entity type.
*
* @see \Drupal\block\Entity\Block
*/
-class BlockAccessControlHandler extends EntityAccessControlHandler {
+class BlockAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
+
+ use ConditionAccessResolverTrait;
+
+ /**
+ * The condition plugin manager.
+ *
+ * @var \Drupal\Core\Executable\ExecutableManagerInterface
+ */
+ protected $manager;
+
+ /**
+ * The plugin context handler.
+ *
+ * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
+ */
+ protected $contextHandler;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
+ return new static(
+ $entity_type,
+ $container->get('plugin.manager.condition'),
+ $container->get('context.handler')
+ );
+ }
+
+ public function __construct(EntityTypeInterface $entity_type, ExecutableManagerInterface $manager, ContextHandlerInterface $context_handler) {
+ parent::__construct($entity_type);
+ $this->manager = $manager;
+ $this->contextHandler = $context_handler;
+ }
+
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
- /** @var $entity \Drupal\block\BlockInterface */
+ /** @var \Drupal\block\BlockInterface $entity */
if ($operation != 'view') {
return parent::checkAccess($entity, $operation, $langcode, $account);
}
@@ -33,8 +75,34 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
return AccessResult::forbidden()->cacheUntilEntityChanges($entity);
}
else {
- // Delegate to the plugin.
- return $entity->getPlugin()->access($account)->cacheUntilEntityChanges($entity);
+ $visibility = $entity->getVisibility();
+ $contexts = $entity->getAvailableContexts();
+ $conditions = array();
+ foreach ($visibility as $condition_id => $configuration) {
+ $condition = $this->manager->createInstance($condition_id, $configuration);
+ if ($condition instanceof ContextAwarePluginInterface) {
+ try {
+ $this->contextHandler->applyContextMapping($condition, $contexts);
+ }
+ catch (ContextException $e) {
+ $access = AccessResult::forbidden();
+ return $access->setCacheable(FALSE)->cacheUntilEntityChanges($entity);
+ }
+ }
+ $conditions[$condition_id] = $condition;
+ }
+ // This should not be hardcoded to an uncacheable access check result, but
+ // in order to fix that, we need condition plugins to return cache contexts,
+ // otherwise it will be impossible to determine by which cache contexts the
+ // result should be varied.
+ if ($this->resolveConditions($conditions, 'and') !== FALSE) {
+ // Delegate to the plugin.
+ $access = $entity->getPlugin()->access($account);
+ }
+ else {
+ $access = AccessResult::forbidden();
+ }
+ return $access->setCacheable(FALSE)->cacheUntilEntityChanges($entity);
}
}
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 73e7ea4..1a7d1f4 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -7,11 +7,16 @@
namespace Drupal\block;
+use Drupal\block\Event\BlockConditionContextEvent;
+use Drupal\block\Event\BlockContextEvent;
+use Drupal\block\Event\BlockEvents;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Executable\ExecutableManagerInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Provides form for block instance forms.
@@ -33,13 +38,29 @@ class BlockForm extends EntityForm {
protected $storage;
/**
+ * The condition plugin manager.
+ *
+ * @var \Drupal\Core\Condition\ConditionManager
+ */
+ protected $manager;
+
+ /**
+ * The event dispatcher service.
+ *
+ * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
+ */
+ protected $dispatcher;
+
+ /**
* Constructs a BlockForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
- public function __construct(EntityManagerInterface $entity_manager) {
+ public function __construct(EntityManagerInterface $entity_manager, ExecutableManagerInterface $manager, EventDispatcherInterface $dispatcher) {
$this->storage = $entity_manager->getStorage('block');
+ $this->manager = $manager;
+ $this->dispatcher = $dispatcher;
}
/**
@@ -47,7 +68,9 @@ public function __construct(EntityManagerInterface $entity_manager) {
*/
public static function create(ContainerInterface $container) {
return new static(
- $container->get('entity.manager')
+ $container->get('entity.manager'),
+ $container->get('plugin.manager.condition'),
+ $container->get('event_dispatcher')
);
}
@@ -62,9 +85,66 @@ public function form(array $form, FormStateInterface $form_state) {
$theme = $this->config('system.theme')->get('default');
}
$form_state->set('block_theme', $theme);
+ $contexts = $this->dispatcher->dispatch(BlockEvents::ADMINISTRATIVE_CONTEXT, new BlockContextEvent())->getContexts();
+ $form_state->set('context_mapping', $contexts);
$form['#tree'] = TRUE;
$form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state);
+ $form['settings']['visibility_tabs'] = array(
+ '#type' => 'vertical_tabs',
+ '#title' => $this->t('Visibility'),
+ '#parents' => array('visibility_tabs'),
+ '#attached' => array(
+ 'library' => array(
+ 'block/drupal.block',
+ ),
+ ),
+ );
+ // @todo Allow list of conditions to be configured in
+ // https://drupal.org/node/2284687.
+ $visibility = $this->entity->getVisibility();
+ foreach ($this->manager->getDefinitions() as $condition_id => $defintion) {
+ // Don't display the current theme condition.
+ if ($condition_id == 'current_theme') {
+ continue;
+ }
+ $condition = $this->manager->createInstance($condition_id, isset($visibility[$condition_id]) ? $visibility[$condition_id] : array());
+ $form_state->set(['conditions', $condition_id], $condition);
+ $condition_form = $condition->buildConfigurationForm(array(), $form_state);
+ $condition_form['#type'] = 'details';
+ $condition_form['#title'] = $condition->getPluginDefinition()['label'];
+ $condition_form['#group'] = 'visibility_tabs';
+ $form['visibility'][$condition_id] = $condition_form;
+ }
+
+ // @todo Determine if there is a better way to rename the conditions.
+ if (isset($form['visibility']['node_type'])) {
+ $form['visibility']['node_type']['#title'] = $this->t('Content types');
+ $form['visibility']['node_type']['bundles']['#title'] = $this->t('Content types');
+ $form['visibility']['node_type']['negate']['#type'] = 'value';
+ $form['visibility']['node_type']['negate']['#title_display'] = 'invisible';
+ $form['visibility']['node_type']['negate']['#value'] = $form['visibility']['node_type']['negate']['#default_value'];
+ }
+ if (isset($form['visibility']['user_role'])) {
+ $form['visibility']['user_role']['#title'] = $this->t('Roles');
+ unset($form['visibility']['user_role']['roles']['#description']);
+ $form['visibility']['user_role']['negate']['#type'] = 'value';
+ $form['visibility']['user_role']['negate']['#value'] = $form['visibility']['user_role']['negate']['#default_value'];
+ }
+ if (isset($form['visibility']['request_path'])) {
+ $form['visibility']['request_path']['#title'] = $this->t('Pages');
+ $form['visibility']['request_path']['negate']['#type'] = 'radios';
+ $form['visibility']['request_path']['negate']['#title_display'] = 'invisible';
+ $form['visibility']['request_path']['negate']['#default_value'] = (int) $form['visibility']['request_path']['negate']['#default_value'];
+ $form['visibility']['request_path']['negate']['#options'] = array(
+ $this->t('Show for the listed pages'),
+ $this->t('Hide for the listed pages'),
+ );
+ }
+ if (isset($form['visibility']['language'])) {
+ $form['visibility']['language']['negate']['#type'] = 'value';
+ $form['visibility']['language']['negate']['#value'] = $form['visibility']['language']['negate']['#default_value'];
+ }
// If creating a new block, calculate a safe default machine name.
$form['id'] = array(
@@ -121,6 +201,7 @@ public function form(array $form, FormStateInterface $form_state) {
$form['#attached']['css'] = array(
drupal_get_path('module', 'block') . '/css/block.admin.css',
);
+ $form_state->set('context_mapping', []);
return $form;
}
@@ -154,6 +235,24 @@ public function validate(array $form, FormStateInterface $form_state) {
$this->entity->getPlugin()->validateConfigurationForm($form, $settings);
// Update the original form values.
$form_state->setValue('settings', $settings->getValues());
+ // Validate visibility condition settings.
+ foreach ($form_state->getValue('visibility') as $condition_id => $values) {
+ if ($this->clearInvalidConditions($values)) {
+ // Allow the condition to validate the form.
+ $condition = $form_state->get(['conditions', $condition_id]);
+ $condition_values = (new FormState())
+ ->setValues($values);
+ $condition->validateConfigurationForm($form, $condition_values);
+ // Update the original form values.
+ $form_state->setValue(['visibility', $condition_id], $condition_values->getValues());
+ }
+ else {
+ $form_state->unsetValue(['visibility', $condition_id]);
+ }
+ }
+ if (!$form_state->hasValue('visibility')) {
+ $form_state->setValue('visibility', array());
+ }
}
/**
@@ -173,6 +272,21 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Update the original form values.
$form_state->setValue('settings', $settings->getValues());
+ // Submit visibility condition settings.
+ foreach ($form_state->getValue('visibility') as $condition_id => $values) {
+ if ($this->clearInvalidConditions($values)) {
+ // Allow the condition to submit the form.
+ $condition = $form_state->get(['conditions', $condition_id]);
+ $condition_values = (new FormState())
+ ->setValues($values);
+ $condition->submitConfigurationForm($form, $condition_values);
+ // Update the original form values.
+ $form_state->setValue(['visibility', $condition_id], $condition->getConfiguration());
+ }
+ }
+
+ $entity->setVisibility($form_state->getValue('visibility'));
+
// Save the settings of the plugin.
$entity->save();
@@ -218,4 +332,33 @@ public function getUniqueMachineName(BlockInterface $block) {
return $machine_default;
}
+ /**
+ * Attempts to determine if a set of values are relevant for a condition.
+ *
+ * @param array $values
+ * The values of a particular condition plugin configuration.
+ *
+ * @return array
+ * The validated array. If empty array, the values are not valid.
+ */
+ protected function clearInvalidConditions($values) {
+ if (isset($values['context_mapping'])) {
+ unset($values['context_mapping']);
+ }
+ // Remove empty values.
+ $values = array_filter($values);
+ foreach ($values as $key => $value) {
+ if (is_array($value)) {
+ $value = $this->clearInvalidConditions($value);
+ if (empty($value)) {
+ unset($values[$key]);
+ }
+ else {
+ $values[$key] = $value;
+ }
+ }
+ }
+ return $values;
+ }
+
}
diff --git a/core/modules/block/src/BlockInterface.php b/core/modules/block/src/BlockInterface.php
index 432e799..9604f08 100644
--- a/core/modules/block/src/BlockInterface.php
+++ b/core/modules/block/src/BlockInterface.php
@@ -40,4 +40,42 @@ public function getPlugin();
*/
public function getVisibility();
+ /**
+ * Sets the visibility configurations for specified conditions.
+ *
+ * @param array $visibility
+ * An array of plugin_id keys and configuration values.
+ *
+ * @return $this
+ */
+ public function setVisibility(array $visibility);
+
+ /**
+ * Sets the visibility condition configuration.
+ *
+ * @param string $instance_id
+ * The condition instance ID.
+ * @param array $configuration
+ * The condition configuration.
+ *
+ * @return $this
+ */
+ public function setVisibilityConfig($instance_id, array $configuration);
+
+ /**
+ * Get all available contexts.
+ *
+ * @return \Drupal\Component\Plugin\Context\ContextInterface[]
+ * An array of set contexts, keyed by context name.
+ */
+ public function getAvailableContexts();
+
+ /**
+ * Set the contexts that are available for use within the block entity.
+ *
+ * @param array $contexts
+ * @return mixed
+ */
+ public function setAvailableContexts(array $contexts);
+
}
diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
index 6f7f276..0df7b2b 100644
--- a/core/modules/block/src/Entity/Block.php
+++ b/core/modules/block/src/Entity/Block.php
@@ -7,13 +7,17 @@
namespace Drupal\block\Entity;
-use Drupal\Core\Cache\Cache;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\block\BlockPluginCollection;
use Drupal\block\BlockInterface;
+use Drupal\block\Event\BlockContextEvent;
+use Drupal\block\Event\BlockEvents;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\EntityWithPluginBagsInterface;
+use Drupal\Core\Cache\Cache;
/**
* Defines a Block configuration entity class.
@@ -78,6 +82,13 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
protected $plugin;
/**
+ * The visibility settings for this block.
+ *
+ * @var array
+ */
+ protected $visibility = array();
+
+ /**
* The plugin collection that holds the block plugin for this entity.
*
* @var \Drupal\block\BlockPluginCollection
@@ -85,6 +96,13 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
protected $pluginCollection;
/**
+ * The available contexts for this block and its visibility conditions.
+ *
+ * @var array
+ */
+ protected $contexts = array();
+
+ /**
* {@inheritdoc}
*/
public function getPlugin() {
@@ -186,8 +204,38 @@ public function getCacheTags() {
/**
* {@inheritdoc}
*/
+ public function setAvailableContexts(array $contexts) {
+ $this->contexts = $contexts;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getAvailableContexts() {
+ return $this->contexts;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getVisibility() {
- return $this->getPlugin()->getVisibilityConditions()->getConfiguration();
+ return $this->visibility;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setVisibility(array $visibility) {
+ $this->visibility = $visibility;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setVisibilityConfig($instance_id, array $configuration) {
+ $this->visibility[$instance_id] = $configuration;
+ return $this;
}
}
diff --git a/core/modules/block/src/Event/BlockConditionContextEvent.php b/core/modules/block/src/Event/BlockConditionContextEvent.php
deleted file mode 100644
index af155b7..0000000
--- a/core/modules/block/src/Event/BlockConditionContextEvent.php
+++ /dev/null
@@ -1,39 +0,0 @@
-conditions = $conditions;
- }
-
- /**
- * @return \Drupal\Core\Block\BlockPluginInterface
- */
- public function getConditions() {
- return $this->conditions;
- }
-
-}
diff --git a/core/modules/block/src/Event/BlockContextEvent.php b/core/modules/block/src/Event/BlockContextEvent.php
new file mode 100644
index 0000000..4889835
--- /dev/null
+++ b/core/modules/block/src/Event/BlockContextEvent.php
@@ -0,0 +1,36 @@
+contexts[$name] = $context;
+ }
+
+ public function getContexts() {
+ return $this->contexts;
+ }
+
+}
diff --git a/core/modules/block/src/Event/BlockEvents.php b/core/modules/block/src/Event/BlockEvents.php
index 8d71c07..22d3e90 100644
--- a/core/modules/block/src/Event/BlockEvents.php
+++ b/core/modules/block/src/Event/BlockEvents.php
@@ -16,8 +16,16 @@
* Name of the event when gathering condition context for a block plugin.
*
* @see \Drupal\Core\Block\BlockBase::getConditionContexts()
- * @see \Drupal\block\Event\BlockConditionContextEvent
+ * @see \Drupal\block\Event\BlockContextEvent
*/
- const CONDITION_CONTEXT = 'block.condition_context';
+ const ACTIVE_CONTEXT = 'block.active_context';
+
+ /**
+ * Name of the event when gathering contexts for plugin configuration.
+ *
+ * @see \Drupal\block\BlockForm::form()
+ * @see \Drupal\block\Event\BlockContextEvent
+ */
+ const ADMINISTRATIVE_CONTEXT = 'block.administrative_context';
}
diff --git a/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php b/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php
deleted file mode 100644
index 9fc2e87..0000000
--- a/core/modules/block/src/EventSubscriber/BlockConditionContextSubscriberBase.php
+++ /dev/null
@@ -1,61 +0,0 @@
-conditions = $event->getConditions();
- $this->determineBlockContext();
- }
-
- /**
- * Determines the contexts for a given block.
- */
- abstract protected function determineBlockContext();
-
- /**
- * Sets the condition context for a given name.
- *
- * @param string $name
- * The name of the context.
- * @param \Drupal\Component\Plugin\Context\ContextInterface $context
- * The context to add.
- *
- * @return $this
- */
- public function addContext($name, ContextInterface $context) {
- $this->conditions->addContext($name, $context);
- return $this;
- }
-
-}
diff --git a/core/modules/block/src/EventSubscriber/BlockContextSubscriberBase.php b/core/modules/block/src/EventSubscriber/BlockContextSubscriberBase.php
new file mode 100644
index 0000000..ddfbf46
--- /dev/null
+++ b/core/modules/block/src/EventSubscriber/BlockContextSubscriberBase.php
@@ -0,0 +1,46 @@
+t('Current language')));
- $context->setContextValue($this->languageManager->getCurrentLanguage());
- $this->addContext('language', $context);
+ public function onBlockActiveContext(BlockContextEvent $event) {
+ // Add a context for each language type.
+ $language_types = $this->languageManager->getLanguageTypes();
+ $info = $this->languageManager->getDefinedLanguageTypesInfo();
+ foreach ($language_types as $type_key) {
+ if (isset($info[$type_key]['name'])) {
+ $context = new Context(new ContextDefinition('language', $info[$type_key]['name']));
+ $context->setContextValue($this->languageManager->getCurrentLanguage($type_key));
+ $event->setContext($type_key, $context);
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onBlockAdministrativeContext(BlockContextEvent $event) {
+ $this->onBlockActiveContext($event);
}
}
diff --git a/core/modules/block/src/EventSubscriber/CurrentUserContext.php b/core/modules/block/src/EventSubscriber/CurrentUserContext.php
index 2a5a19e..b16f2c1 100644
--- a/core/modules/block/src/EventSubscriber/CurrentUserContext.php
+++ b/core/modules/block/src/EventSubscriber/CurrentUserContext.php
@@ -7,6 +7,7 @@
namespace Drupal\block\EventSubscriber;
+use Drupal\block\Event\BlockContextEvent;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
@@ -16,7 +17,7 @@
/**
* Sets the current user as a context.
*/
-class CurrentUserContext extends BlockConditionContextSubscriberBase {
+class CurrentUserContext extends BlockContextSubscriberBase {
use StringTranslationTrait;
@@ -50,12 +51,19 @@ public function __construct(AccountInterface $account, EntityManagerInterface $e
/**
* {@inheritdoc}
*/
- protected function determineBlockContext() {
+ public function onBlockActiveContext(BlockContextEvent $event) {
$current_user = $this->userStorage->load($this->account->id());
$context = new Context(new ContextDefinition('entity:user', $this->t('Current user')));
$context->setContextValue($current_user);
- $this->addContext('current_user', $context);
+ $event->setContext('current_user', $context);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onBlockAdministrativeContext(BlockContextEvent $event) {
+ $this->onBlockActiveContext($event);
}
}
diff --git a/core/modules/block/src/EventSubscriber/NodeRouteContext.php b/core/modules/block/src/EventSubscriber/NodeRouteContext.php
index c1bd2bf..cfa06a0 100644
--- a/core/modules/block/src/EventSubscriber/NodeRouteContext.php
+++ b/core/modules/block/src/EventSubscriber/NodeRouteContext.php
@@ -7,6 +7,7 @@
namespace Drupal\block\EventSubscriber;
+use Drupal\block\Event\BlockContextEvent;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Routing\RouteMatchInterface;
@@ -15,7 +16,7 @@
/**
* Sets the current node as a context on node routes.
*/
-class NodeRouteContext extends BlockConditionContextSubscriberBase {
+class NodeRouteContext extends BlockContextSubscriberBase {
/**
* The route match object.
@@ -37,20 +38,28 @@ public function __construct(RouteMatchInterface $route_match) {
/**
* {@inheritdoc}
*/
- protected function determineBlockContext() {
+ public function onBlockActiveContext(BlockContextEvent $event) {
if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
$context = new Context(new ContextDefinition($route_contexts['node']['type']));
if ($node = $this->routeMatch->getParameter('node')) {
$context->setContextValue($node);
}
- $this->addContext('node', $context);
+ $event->setContext('node', $context);
}
elseif ($this->routeMatch->getRouteName() == 'node.add') {
$node_type = $this->routeMatch->getParameter('node_type');
$context = new Context(new ContextDefinition('entity:node'));
$context->setContextValue(Node::create(array('type' => $node_type->id())));
- $this->addContext('node', $context);
+ $event->setContext('node', $context);
}
}
+ /**
+ * {@inheritdoc}
+ */
+ public function onBlockAdministrativeContext(BlockContextEvent $event) {
+ $context = new Context(new ContextDefinition('entity:node'));
+ $event->setContext('node', $context);
+ }
+
}
diff --git a/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php
index 7243362..e038024 100644
--- a/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php
+++ b/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php
@@ -7,13 +7,18 @@
namespace Drupal\block\Plugin\DisplayVariant;
+use Drupal\block\Event\BlockContextEvent;
+use Drupal\block\Event\BlockEvents;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Display\VariantBase;
+use Drupal\Core\Plugin\Context\ContextHandlerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Provides a display variant that represents the full page.
@@ -77,13 +82,19 @@ class FullPageVariant extends VariantBase implements ContainerFactoryPluginInter
* The current route match.
* @param \Drupal\Core\Theme\ThemeNegotiatorInterface $theme_negotiator
* The theme negotiator.
+ * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
+ * The event dispatcher.
+ * @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
+ * The plugin context handler.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $block_storage, EntityViewBuilderInterface $block_view_builder, RouteMatchInterface $route_match, ThemeNegotiatorInterface $theme_negotiator) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $block_storage, EntityViewBuilderInterface $block_view_builder, RouteMatchInterface $route_match, ThemeNegotiatorInterface $theme_negotiator, EventDispatcherInterface $dispatcher, ContextHandlerInterface $context_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->blockStorage = $block_storage;
$this->blockViewBuilder = $block_view_builder;
$this->routeMatch = $route_match;
$this->themeNegotiator = $theme_negotiator;
+ $this->dispatcher = $dispatcher;
+ $this->contextHandler = $context_handler;
}
/**
@@ -97,7 +108,9 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('entity.manager')->getStorage('block'),
$container->get('entity.manager')->getViewBuilder('block'),
$container->get('current_route_match'),
- $container->get('theme.negotiator')
+ $container->get('theme.negotiator'),
+ $container->get('event_dispatcher'),
+ $container->get('context.handler')
);
}
@@ -116,11 +129,20 @@ protected function getTheme() {
*/
public function build() {
$build = array();
+
+ $event = new BlockContextEvent();
+ $this->dispatcher->dispatch(BlockEvents::ACTIVE_CONTEXT, $event);
+ $contexts = $event->getContexts();
// Load all region content assigned via blocks.
foreach ($this->getRegionAssignments() as $region => $blocks) {
/** @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $key => $block) {
+ $block->setAvailableContexts($contexts);
if ($block->access('view')) {
+ $block_plugin = $block->getPlugin();
+ if ($block_plugin instanceof ContextAwarePluginInterface) {
+ $this->contextHandler->applyContextMapping($block_plugin, $contexts);
+ }
$build[$region][$key] = $this->blockViewBuilder->view($block);
}
}
diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php
index 7361f96..3c7ecb0 100644
--- a/core/modules/block/src/Tests/BlockInterfaceTest.php
+++ b/core/modules/block/src/Tests/BlockInterfaceTest.php
@@ -39,7 +39,6 @@ public function testBlockInterface() {
'label' => 'Custom Display Message',
);
$expected_configuration = array(
- 'visibility' => array(),
'id' => 'test_block_instantiation',
'label' => 'Custom Display Message',
'provider' => 'block_test',
diff --git a/core/modules/block/src/Tests/BlockLanguageTest.php b/core/modules/block/src/Tests/BlockLanguageTest.php
index 380c65c..500b392 100644
--- a/core/modules/block/src/Tests/BlockLanguageTest.php
+++ b/core/modules/block/src/Tests/BlockLanguageTest.php
@@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
+use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\block\Entity\Block;
@@ -53,11 +54,11 @@ public function testLanguageBlockVisibility() {
$default_theme = \Drupal::config('system.theme')->get('default');
$this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
- $this->assertField('settings[visibility][language][langcodes][en]', 'Language visibility field is visible.');
+ $this->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.');
// Enable a standard block and set the visibility setting for one language.
$edit = array(
- 'settings[visibility][language][langcodes][en]' => TRUE,
+ 'visibility[language][langcodes][en]' => TRUE,
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
);
@@ -69,11 +70,11 @@ public function testLanguageBlockVisibility() {
);
$this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration'));
- // Check that a page has a block.
+ // Check that a page has the block.
$this->drupalGet('en');
$this->assertText('Powered by Drupal', 'The body of the custom block appears on the page.');
- // Check that a page doesn't has a block for the current language anymore.
+ // Check that the page in a different language does not have the block.
$this->drupalGet('fr');
$this->assertNoText('Powered by Drupal', 'The body of the custom block does not appear on the page.');
}
@@ -86,7 +87,6 @@ public function testLanguageBlockVisibilityLanguageDelete() {
$edit = array(
'visibility' => array(
'language' => array(
- 'language_type' => 'language_interface',
'langcodes' => array(
'fr' => 'fr',
),
@@ -97,8 +97,7 @@ public function testLanguageBlockVisibilityLanguageDelete() {
// Check that we have the language in config after saving the setting.
$visibility = $block->getVisibility();
- $language = $visibility['language']['langcodes']['fr'];
- $this->assertTrue('fr' === $language, 'Language is set in the block configuration.');
+ $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'));
diff --git a/core/modules/block/src/Tests/BlockStorageUnitTest.php b/core/modules/block/src/Tests/BlockStorageUnitTest.php
index 5fb4e8b..6d0c928 100644
--- a/core/modules/block/src/Tests/BlockStorageUnitTest.php
+++ b/core/modules/block/src/Tests/BlockStorageUnitTest.php
@@ -26,7 +26,7 @@ class BlockStorageUnitTest extends DrupalUnitTestBase {
*
* @var array
*/
- public static $modules = array('block', 'block_test', 'system');
+ public static $modules = array('block', 'block_test');
/**
* The block storage.
@@ -94,7 +94,6 @@ protected function createTests() {
'provider' => NULL,
'plugin' => 'test_html',
'settings' => array(
- 'visibility' => array(),
'id' => 'test_html',
'label' => '',
'provider' => 'block_test',
@@ -104,6 +103,7 @@ protected function createTests() {
'contexts' => array(),
),
),
+ 'visibility' => array(),
);
$this->assertIdentical($actual_properties, $expected_properties);
diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php
index 1996c9b..b4df387 100644
--- a/core/modules/block/src/Tests/BlockTest.php
+++ b/core/modules/block/src/Tests/BlockTest.php
@@ -35,9 +35,9 @@ function testBlockVisibility() {
);
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
- $edit['settings[visibility][request_path][pages]'] = 'user*';
- $edit['settings[visibility][request_path][negate]'] = TRUE;
- $edit['settings[visibility][user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
+ $edit['visibility[request_path][pages]'] = 'user*';
+ $edit['visibility[request_path][negate]'] = TRUE;
+ $edit['visibility[user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
$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');
@@ -73,7 +73,7 @@ function testBlockVisibilityListedEmpty() {
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
'settings[label]' => $title,
- 'settings[visibility][request_path][negate]' => TRUE,
+ 'visibility[request_path][negate]' => TRUE,
);
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
diff --git a/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml b/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
index 72510d0..f52790f 100644
--- a/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
+++ b/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
@@ -6,7 +6,6 @@ langcode: en
region: '-1'
plugin: test_html
settings:
- visibility: { }
label: 'Test HTML block'
provider: block_test
label_display: 'hidden'
@@ -15,3 +14,4 @@ dependencies:
- block_test
theme:
- stark
+visibility: { }
diff --git a/core/modules/block/tests/src/Unit/BlockFormTest.php b/core/modules/block/tests/src/Unit/BlockFormTest.php
index 0860f93..d10d005 100644
--- a/core/modules/block/tests/src/Unit/BlockFormTest.php
+++ b/core/modules/block/tests/src/Unit/BlockFormTest.php
@@ -49,11 +49,11 @@ public function testGetUniqueMachineName() {
->method('getStorage')
->will($this->returnValue($block_storage));
- $language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
+ $condition_manager = $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface');
- $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
+ $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $block_form_controller = new BlockForm($entity_manager, $language_manager, $config_factory);
+ $block_form_controller = new BlockForm($entity_manager, $condition_manager, $event_dispatcher);
// Ensure that the block with just one other instance gets the next available
// name suggestion.
diff --git a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/FullPageVariantTest.php b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/FullPageVariantTest.php
index 1cbcfe5..24272a2 100644
--- a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/FullPageVariantTest.php
+++ b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/FullPageVariantTest.php
@@ -44,6 +44,20 @@ class FullPageVariantTest extends UnitTestCase {
protected $themeNegotiator;
/**
+ * The event dispatcher.
+ *
+ * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $dispatcher;
+
+ /**
+ * The plugin context handler.
+ *
+ * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $contextHandler;
+
+ /**
* Sets up a display variant plugin for testing.
*
* @param array $configuration
@@ -59,8 +73,10 @@ public function setUpDisplayVariant($configuration = array(), $definition = arra
$this->blockViewBuilder = $this->getMock('Drupal\Core\Entity\EntityViewBuilderInterface');
$this->routeMatch = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
$this->themeNegotiator = $this->getMock('Drupal\Core\Theme\ThemeNegotiatorInterface');
+ $this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $this->contextHandler = $this->getMock('Drupal\Core\Plugin\Context\ContextHandlerInterface');
return $this->getMockBuilder('Drupal\block\Plugin\DisplayVariant\FullPageVariant')
- ->setConstructorArgs(array($configuration, 'test', $definition, $this->blockStorage, $this->blockViewBuilder, $this->routeMatch, $this->themeNegotiator))
+ ->setConstructorArgs(array($configuration, 'test', $definition, $this->blockStorage, $this->blockViewBuilder, $this->routeMatch, $this->themeNegotiator, $this->dispatcher, $this->contextHandler))
->setMethods(array('getRegionNames'))
->getMock();
}
diff --git a/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.foobargorilla.yml b/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.foobargorilla.yml
index b8b7827..a39088a 100644
--- a/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.foobargorilla.yml
+++ b/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.foobargorilla.yml
@@ -12,11 +12,6 @@ weight: null
provider: null
plugin: 'block_content:fb5e8434-3617-4a1d-a252-8273e95ec30e'
settings:
- visibility:
- request_path:
- id: request_path
- pages: ''
- negate: false
id: 'block_content:fb5e8434-3617-4a1d-a252-8273e95ec30e'
label: 'Foobar Gorilla'
provider: block_content
@@ -27,3 +22,8 @@ settings:
status: true
info: ''
view_mode: default
+visibility:
+ request_path:
+ id: request_path
+ pages: ''
+ negate: false
diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php
index 0f46dd5..914275d 100644
--- a/core/modules/language/src/Plugin/Condition/Language.php
+++ b/core/modules/language/src/Plugin/Condition/Language.php
@@ -31,23 +31,23 @@ class Language extends ConditionPluginBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
if (\Drupal::languageManager()->isMultilingual()) {
// Fetch languages.
- $languages = language_list(LanguageInterface::STATE_CONFIGURABLE);
+ $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
$langcodes_options = array();
foreach ($languages as $language) {
$langcodes_options[$language->getId()] = $language->getName();
}
$form['langcodes'] = array(
'#type' => 'checkboxes',
- '#title' => t('Language selection'),
- '#default_value' => $this->configuration['langcodes'],
+ '#title' => $this->t('Language selection'),
+ '#default_value' => !empty($this->configuration['langcodes']) ? $this->configuration['langcodes'] : array(),
'#options' => $langcodes_options,
- '#description' => t('Select languages to enforce. If none are selected, all languages will be allowed.'),
+ '#description' => $this->t('Select languages to enforce. If none are selected, all languages will be allowed.'),
);
}
else {
$form['langcodes'] = array(
'#type' => 'value',
- '#value' => $this->configuration['langcodes'],
+ '#value' => !empty($this->configuration['langcodes']) ? $this->configuration['langcodes'] : array(),
);
}
return parent::buildConfigurationForm($form, $form_state);
@@ -98,17 +98,9 @@ public function evaluate() {
if (empty($this->configuration['langcodes']) && !$this->isNegated()) {
return TRUE;
}
-
$language = $this->getContextValue('language');
// Language visibility settings.
return !empty($this->configuration['langcodes'][$language->getId()]);
}
- /**
- * {@inheritdoc}
- */
- public function defaultConfiguration() {
- return array('langcodes' => array()) + parent::defaultConfiguration();
- }
-
}
diff --git a/core/modules/language/src/Tests/LanguageBlockSettingsVisibilityTest.php b/core/modules/language/src/Tests/LanguageBlockSettingsVisibilityTest.php
index e1f9cb9..cac5b51 100644
--- a/core/modules/language/src/Tests/LanguageBlockSettingsVisibilityTest.php
+++ b/core/modules/language/src/Tests/LanguageBlockSettingsVisibilityTest.php
@@ -23,9 +23,9 @@ public function testUnnecessaryLanguageSettingsVisibility() {
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'hu'), t('Add language'));
$this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark');
- $this->assertNoFieldByXPath('//input[@id="edit-settings-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
- $this->assertNoFieldByXpath('//input[@id="edit-settings-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
- $this->assertFieldByXPath('//input[@id="edit-settings-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
- $this->assertFieldByXpath('//input[@id="edit-settings-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
+ $this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
+ $this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
+ $this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
+ $this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
}
}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php
index 4b15b05..fb7f6d9 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockTest.php
@@ -91,8 +91,7 @@ public function testBlockMigration() {
$this->assertEqual('sidebar_first', $test_block_user->get('region'));
$this->assertEqual('bartik', $test_block_user->get('theme'));
$visibility = $test_block_user->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(0, $test_block_user->weight);
$test_block_user_1 = $blocks['user_1'];
@@ -100,8 +99,7 @@ public function testBlockMigration() {
$this->assertEqual('sidebar_first', $test_block_user_1->get('region'));
$this->assertEqual('bartik', $test_block_user_1->get('theme'));
$visibility = $test_block_user_1->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(0, $test_block_user_1->weight);
// Check system block
@@ -110,8 +108,7 @@ public function testBlockMigration() {
$this->assertEqual('footer', $test_block_system->get('region'));
$this->assertEqual('bartik', $test_block_system->get('theme'));
$visibility = $test_block_system->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(-5, $test_block_system->weight);
// Check menu blocks
@@ -120,8 +117,7 @@ public function testBlockMigration() {
$this->assertEqual('header', $test_block_menu->get('region'));
$this->assertEqual('bartik', $test_block_menu->get('theme'));
$visibility = $test_block_menu->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(-5, $test_block_menu->weight);
// Check custom blocks
@@ -130,8 +126,7 @@ public function testBlockMigration() {
$this->assertEqual('content', $test_block_block->get('region'));
$this->assertEqual('bartik', $test_block_block->get('theme'));
$visibility = $test_block_block->getVisibility();
- $this->assertEqual(FALSE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(0, $test_block_block->weight);
$test_block_block_1 = $blocks['block_1'];
@@ -139,8 +134,7 @@ public function testBlockMigration() {
$this->assertEqual('right', $test_block_block_1->get('region'));
$this->assertEqual('bluemarine', $test_block_block_1->get('theme'));
$visibility = $test_block_block_1->getVisibility();
- $this->assertEqual(FALSE, $visibility['request_path']['negate']);
- $this->assertEqual('node', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(-4, $test_block_block_1->weight);
$test_block_block_2 = $blocks['block_2'];
@@ -148,8 +142,7 @@ public function testBlockMigration() {
$this->assertEqual('right', $test_block_block_2->get('region'));
$this->assertEqual('test_theme', $test_block_block_2->get('theme'));
$visibility = $test_block_block_2->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(-7, $test_block_block_2->weight);
$test_block_block_3 = $blocks['block_3'];
@@ -157,8 +150,7 @@ public function testBlockMigration() {
$this->assertEqual('left', $test_block_block_3->get('region'));
$this->assertEqual('test_theme', $test_block_block_3->get('theme'));
$visibility = $test_block_block_3->getVisibility();
- $this->assertEqual(TRUE, $visibility['request_path']['negate']);
- $this->assertEqual('', $visibility['request_path']['pages']);
+ $this->assertTrue(empty($visibility['request_path']));
$this->assertEqual(-2, $test_block_block_3->weight);
}
}
diff --git a/core/modules/node/src/Plugin/Condition/NodeType.php b/core/modules/node/src/Plugin/Condition/NodeType.php
index 9a2b35b..91211c4 100644
--- a/core/modules/node/src/Plugin/Condition/NodeType.php
+++ b/core/modules/node/src/Plugin/Condition/NodeType.php
@@ -79,7 +79,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#title' => $this->t('Node types'),
'#type' => 'checkboxes',
'#options' => $options,
- '#default_value' => $this->configuration['bundles'],
+ '#default_value' => !empty($this->configuration['bundles']) ? $this->configuration['bundles'] : [],
);
return parent::buildConfigurationForm($form, $form_state);
}
diff --git a/core/modules/search/src/Tests/SearchBlockTest.php b/core/modules/search/src/Tests/SearchBlockTest.php
index cdc7905..9aca60f 100644
--- a/core/modules/search/src/Tests/SearchBlockTest.php
+++ b/core/modules/search/src/Tests/SearchBlockTest.php
@@ -59,7 +59,7 @@ protected function testSearchFormBlock() {
$visibility = $block->getVisibility();
$visibility['request_path']['pages'] = 'search';
- $block->getPlugin()->setVisibilityConfig('request_path', $visibility['request_path']);
+ $block->setVisibilityConfig('request_path', $visibility['request_path']);
$this->submitGetForm('', $terms, t('Search'));
$this->assertResponse(200);
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index 39aeabc..f9fdd77 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -381,13 +381,14 @@ protected function drupalPlaceBlock($plugin_id, array $settings = array()) {
'max_age' => 0,
),
);
- foreach (array('region', 'id', 'theme', 'plugin', 'weight') as $key) {
+ $values = array();
+ foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) {
$values[$key] = $settings[$key];
// Remove extra values that do not belong in the settings array.
unset($settings[$key]);
}
- foreach ($settings['visibility'] as $id => $visibility) {
- $settings['visibility'][$id]['id'] = $id;
+ foreach ($values['visibility'] as $id => $visibility) {
+ $values['visibility'][$id]['id'] = $id;
}
$values['settings'] = $settings;
$block = entity_create('block', $values);
diff --git a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
index 89991ef..3c5ffe5 100644
--- a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
+++ b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
@@ -97,7 +97,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['theme'] = array(
'#type' => 'select',
'#title' => $this->t('Theme'),
- '#default_value' => $this->configuration['theme'],
+ '#default_value' => !empty($this->configuration['theme']) ? $this->configuration['theme'] : '',
'#options' => array_map(function ($theme_info) {
return $theme_info->info['name'];
}, $this->themeHandler->listInfo()),
diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php
index a5f5613..196951c 100644
--- a/core/modules/system/src/Plugin/Condition/RequestPath.php
+++ b/core/modules/system/src/Plugin/Condition/RequestPath.php
@@ -98,7 +98,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['pages'] = array(
'#type' => 'textarea',
'#title' => $this->t('Pages'),
- '#default_value' => $this->configuration['pages'],
+ '#default_value' => !empty($this->configuration['pages']) ? $this->configuration['pages'] : '',
'#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %user for the current user's page and %user-wildcard for every user page. %front is the front page.", array(
'%user' => 'user',
'%user-wildcard' => 'user/*',
diff --git a/core/modules/system/tests/modules/condition_test/src/FormController.php b/core/modules/system/tests/modules/condition_test/src/FormController.php
index 1f13755..870ef83 100644
--- a/core/modules/system/tests/modules/condition_test/src/FormController.php
+++ b/core/modules/system/tests/modules/condition_test/src/FormController.php
@@ -42,6 +42,7 @@ public function __construct() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
+ $form_state->set('context_mapping', []);
$form = $this->condition->buildConfigurationForm($form, $form_state);
$form['actions']['submit'] = array(
'#type' => 'submit',
diff --git a/core/modules/user/src/Plugin/Condition/UserRole.php b/core/modules/user/src/Plugin/Condition/UserRole.php
index 1462c8f..34ec481 100644
--- a/core/modules/user/src/Plugin/Condition/UserRole.php
+++ b/core/modules/user/src/Plugin/Condition/UserRole.php
@@ -32,7 +32,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => $this->t('When the user has the following roles'),
- '#default_value' => $this->configuration['roles'],
+ '#default_value' => !empty($this->configuration['roles']) ? $this->configuration['roles'] : [],
'#options' => array_map('\Drupal\Component\Utility\String::checkPlain', user_role_names()),
'#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),
);
diff --git a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php
index c26ee66..2c03f23 100644
--- a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php
@@ -126,10 +126,6 @@ public function testBuild() {
$definition['provider'] = 'views';
$plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
- $reflector = new \ReflectionClass($plugin);
- $property = $reflector->getProperty('conditionPluginManager');
- $property->setAccessible(TRUE);
- $property->setValue($plugin, $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface'));
$this->assertEquals($build, $plugin->build());
}
@@ -152,10 +148,6 @@ public function testBuildFailed() {
$definition['provider'] = 'views';
$plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
- $reflector = new \ReflectionClass($plugin);
- $property = $reflector->getProperty('conditionPluginManager');
- $property->setAccessible(TRUE);
- $property->setValue($plugin, $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface'));
$this->assertEquals(array(), $plugin->build());
}
diff --git a/core/profiles/minimal/config/install/block.block.stark_admin.yml b/core/profiles/minimal/config/install/block.block.stark_admin.yml
index 0934049..7f011c1 100644
--- a/core/profiles/minimal/config/install/block.block.stark_admin.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_admin.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: 'system_menu_block:admin'
settings:
- visibility: { }
label: Administration
provider: system
label_display: visible
@@ -22,3 +21,4 @@ dependencies:
- system
theme:
- stark
+visibility: { }
diff --git a/core/profiles/minimal/config/install/block.block.stark_login.yml b/core/profiles/minimal/config/install/block.block.stark_login.yml
index 9081e1a..41eba3f 100644
--- a/core/profiles/minimal/config/install/block.block.stark_login.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_login.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: user_login_block
settings:
- visibility: { }
label: 'User login'
provider: user
label_display: visible
@@ -15,3 +14,4 @@ dependencies:
- user
theme:
- stark
+visibility: { }
diff --git a/core/profiles/minimal/config/install/block.block.stark_tools.yml b/core/profiles/minimal/config/install/block.block.stark_tools.yml
index c8268bb..00fed85 100644
--- a/core/profiles/minimal/config/install/block.block.stark_tools.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_tools.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: 'system_menu_block:tools'
settings:
- visibility: { }
label: Tools
provider: system
label_display: visible
@@ -22,3 +21,4 @@ dependencies:
- system
theme:
- stark
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_account_menu.yml b/core/profiles/standard/config/install/block.block.bartik_account_menu.yml
index 37ef707..9ca924f 100644
--- a/core/profiles/standard/config/install/block.block.bartik_account_menu.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_account_menu.yml
@@ -6,7 +6,6 @@ langcode: en
region: secondary_menu
plugin: 'system_menu_block:account'
settings:
- visibility: { }
id: 'system_menu_block:account'
label: 'User account menu'
provider: system
@@ -23,3 +22,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml b/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
index 2128a61..c89b728 100644
--- a/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
@@ -6,7 +6,6 @@ langcode: en
region: '-1'
plugin: system_breadcrumb_block
settings:
- visibility: { }
id: system_breadcrumb_block
label: Breadcrumbs
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_content.yml b/core/profiles/standard/config/install/block.block.bartik_content.yml
index d30a7f3..87d320f 100644
--- a/core/profiles/standard/config/install/block.block.bartik_content.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_content.yml
@@ -6,7 +6,6 @@ langcode: en
region: content
plugin: system_main_block
settings:
- visibility: { }
id: system_main_block
label: 'Main page content'
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_footer.yml b/core/profiles/standard/config/install/block.block.bartik_footer.yml
index 3074b3a..6a1d49c 100644
--- a/core/profiles/standard/config/install/block.block.bartik_footer.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_footer.yml
@@ -6,7 +6,6 @@ langcode: en
region: footer
plugin: 'system_menu_block:footer'
settings:
- visibility: { }
id: 'system_menu_block:footer'
label: 'Footer menu'
provider: system
@@ -23,3 +22,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_help.yml b/core/profiles/standard/config/install/block.block.bartik_help.yml
index 3a2f48a..941fa1b 100644
--- a/core/profiles/standard/config/install/block.block.bartik_help.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_help.yml
@@ -6,7 +6,6 @@ langcode: en
region: help
plugin: system_help_block
settings:
- visibility: { }
id: system_help_block
label: 'System Help'
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_login.yml b/core/profiles/standard/config/install/block.block.bartik_login.yml
index 6d58c23..3a5f543 100644
--- a/core/profiles/standard/config/install/block.block.bartik_login.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_login.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: user_login_block
settings:
- visibility: { }
id: user_login_block
label: 'User login'
provider: user
@@ -16,3 +15,4 @@ dependencies:
- user
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_main_menu.yml b/core/profiles/standard/config/install/block.block.bartik_main_menu.yml
index 90a596f..0e75cd1 100644
--- a/core/profiles/standard/config/install/block.block.bartik_main_menu.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_main_menu.yml
@@ -6,7 +6,6 @@ langcode: en
region: primary_menu
plugin: 'system_menu_block:main'
settings:
- visibility: {}
id: 'system_menu_block:main'
label: 'Main navigation'
provider: system
@@ -23,3 +22,4 @@ dependencies:
- system
theme:
- bartik
+visibility: {}
diff --git a/core/profiles/standard/config/install/block.block.bartik_powered.yml b/core/profiles/standard/config/install/block.block.bartik_powered.yml
index 106c279..5a9881f 100644
--- a/core/profiles/standard/config/install/block.block.bartik_powered.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_powered.yml
@@ -6,7 +6,6 @@ langcode: en
region: footer
plugin: system_powered_by_block
settings:
- visibility: { }
id: system_powered_by_block
label: 'Powered by Drupal'
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_search.yml b/core/profiles/standard/config/install/block.block.bartik_search.yml
index ac4130a..af99dea 100644
--- a/core/profiles/standard/config/install/block.block.bartik_search.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_search.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: search_form_block
settings:
- visibility: { }
id: search_form_block
label: Search
provider: search
@@ -16,3 +15,4 @@ dependencies:
- search
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.bartik_tools.yml b/core/profiles/standard/config/install/block.block.bartik_tools.yml
index 9a4b8b3..a7aa2f6 100644
--- a/core/profiles/standard/config/install/block.block.bartik_tools.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_tools.yml
@@ -6,7 +6,6 @@ langcode: en
region: sidebar_first
plugin: 'system_menu_block:tools'
settings:
- visibility: { }
id: 'system_menu_block:tools'
label: Tools
provider: system
@@ -23,3 +22,4 @@ dependencies:
- system
theme:
- bartik
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml b/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
index cd7d7ac..8ce13d8 100644
--- a/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
+++ b/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
@@ -6,7 +6,6 @@ langcode: en
region: '-1'
plugin: system_breadcrumb_block
settings:
- visibility: { }
id: system_breadcrumb_block
label: Breadcrumbs
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- seven
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.seven_content.yml b/core/profiles/standard/config/install/block.block.seven_content.yml
index 12c2c5f..dd2bfbe 100644
--- a/core/profiles/standard/config/install/block.block.seven_content.yml
+++ b/core/profiles/standard/config/install/block.block.seven_content.yml
@@ -6,7 +6,6 @@ langcode: en
region: content
plugin: system_main_block
settings:
- visibility: { }
id: system_main_block
label: 'Main page content'
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- seven
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.seven_help.yml b/core/profiles/standard/config/install/block.block.seven_help.yml
index 1cf9fa3..168e7f0 100644
--- a/core/profiles/standard/config/install/block.block.seven_help.yml
+++ b/core/profiles/standard/config/install/block.block.seven_help.yml
@@ -6,7 +6,6 @@ langcode: en
region: help
plugin: system_help_block
settings:
- visibility: { }
id: system_help_block
label: 'System Help'
provider: system
@@ -16,3 +15,4 @@ dependencies:
- system
theme:
- seven
+visibility: { }
diff --git a/core/profiles/standard/config/install/block.block.seven_login.yml b/core/profiles/standard/config/install/block.block.seven_login.yml
index 321d92b..0a488a7 100644
--- a/core/profiles/standard/config/install/block.block.seven_login.yml
+++ b/core/profiles/standard/config/install/block.block.seven_login.yml
@@ -6,7 +6,6 @@ langcode: en
region: content
plugin: user_login_block
settings:
- visibility: { }
id: user_login_block
label: 'User login'
provider: user
@@ -16,3 +15,4 @@ dependencies:
- user
theme:
- seven
+visibility: { }
diff --git a/core/profiles/standard/src/Tests/StandardTest.php b/core/profiles/standard/src/Tests/StandardTest.php
index b05285e..10c1e97 100644
--- a/core/profiles/standard/src/Tests/StandardTest.php
+++ b/core/profiles/standard/src/Tests/StandardTest.php
@@ -7,6 +7,7 @@
namespace Drupal\standard\Tests;
+use Drupal\block\Entity\Block;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\simpletest\WebTestBase;
diff --git a/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php b/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
index 028ea73..02a7170 100644
--- a/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
+++ b/core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php
@@ -8,7 +8,6 @@
namespace Drupal\Tests\Core\Block;
use Drupal\block_test\Plugin\Block\TestBlockInstantiation;
-use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
@@ -28,14 +27,6 @@ public function testGetMachineNameSuggestion() {
->setMethods(array('readLanguageOverrides'))
->getMock();
- $condition_plugin_manager = $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface');
- $condition_plugin_manager->expects($this->atLeastOnce())
- ->method('getDefinitions')
- ->will($this->returnValue(array()));
- $container = new ContainerBuilder();
- $container->set('plugin.manager.condition', $condition_plugin_manager);
- \Drupal::setContainer($container);
-
$config = array();
$definition = array(
'admin_label' => 'Admin label',
@@ -55,52 +46,5 @@ public function testGetMachineNameSuggestion() {
$this->assertEquals('uberawesome', $block_base->getMachineNameSuggestion());
}
- /**
- * Tests initializing the condition plugins initialization.
- */
- public function testConditionsBagInitialization() {
- $plugin_manager = $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface');
- $plugin_manager->expects($this->once())
- ->method('getDefinitions')
- ->will($this->returnValue(array(
- 'request_path' => array(
- 'id' => 'request_path',
- ),
- 'user_role' => array(
- 'id' => 'user_role',
- ),
- 'node_type' => array(
- 'id' => 'node_type',
- ),
- 'language' => array(
- 'id' => 'language',
- ),
- )));
- $container = new ContainerBuilder();
- $container->set('plugin.manager.condition', $plugin_manager);
- \Drupal::setContainer($container);
- $config = array();
- $definition = array(
- 'admin_label' => 'Admin label',
- 'provider' => 'block_test',
- );
-
- $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
- $conditions_collection = $block_base->getVisibilityConditions();
-
- $this->assertEquals(4, $conditions_collection->count(), "There are 4 condition plugins");
-
- $instance_id = $this->randomMachineName();
- $pages = 'node/1';
- $condition_config = array('id' => 'request_path', 'pages' => $pages);
- $block_base->setVisibilityConfig($instance_id, $condition_config);
-
- $plugin_manager->expects($this->once())->method('createInstance')
- ->withAnyParameters()->will($this->returnValue('test'));
-
- $condition = $block_base->getVisibilityCondition($instance_id);
-
- $this->assertEquals('test', $condition, "The correct condition is returned.");
- }
-
}
+