diff --git a/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php b/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php index b0d4a8d8a1e..cb08ef10962 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php @@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a 'Entity Bundle' condition. + * Provides the 'Entity Bundle' condition. * * @Condition( * id = "entity_bundle", @@ -26,20 +26,6 @@ class EntityBundle extends ConditionPluginBase implements ContainerFactoryPlugin */ protected $entityTypeBundleInfo; - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The entity type containing the bundles. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - /** * Creates a new EntityBundle instance. * @@ -52,16 +38,12 @@ class EntityBundle extends ConditionPluginBase implements ContainerFactoryPlugin * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info * The entity type bundle info service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $entity_type_bundle_info) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityTypeManager = $entity_type_manager; $this->entityTypeBundleInfo = $entity_type_bundle_info; - $this->entityType = $entity_type_manager->getDefinition($this->getDerivativeId()); } /** @@ -72,7 +54,6 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity_type.manager'), $container->get('entity_type.bundle.info') ); } @@ -81,7 +62,7 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->entityType->id()); + $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->getDerivativeId()); $form['bundles'] = [ '#title' => $this->pluginDefinition['label'], '#type' => 'checkboxes', @@ -108,7 +89,7 @@ public function evaluate() { return TRUE; } /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $this->getContextValue($this->entityType->id()); + $entity = $this->getContextValue($this->getDerivativeId()); return !empty($this->configuration['bundles'][$entity->bundle()]); } @@ -116,7 +97,6 @@ public function evaluate() { * {@inheritdoc} */ public function summary() { - $bundle_type = $this->entityType->getBundleLabel(); if (count($this->configuration['bundles']) > 1) { $bundles = $this->configuration['bundles']; $last = array_pop($bundles); @@ -124,14 +104,14 @@ public function summary() { if (empty($this->configuration['negate'])) { return $this->t('@bundle_type is @bundles or @last', [ - '@bundle_type' => $bundle_type, + '@bundle_type' => $this->pluginDefinition['label'], '@bundles' => $bundles, '@last' => $last, ]); } else { return $this->t('@bundle_type is not @bundles or @last', [ - '@bundle_type' => $bundle_type, + '@bundle_type' => $this->pluginDefinition['label'], '@bundles' => $bundles, '@last' => $last, ]); @@ -142,13 +122,13 @@ public function summary() { if (empty($this->configuration['negate'])) { return $this->t('@bundle_type is @bundle', [ - '@bundle_type' => $bundle_type, + '@bundle_type' => $this->pluginDefinition['label'], '@bundle' => $bundle, ]); } else { return $this->t('@bundle_type is not @bundle', [ - '@bundle_type' => $bundle_type, + '@bundle_type' => $this->pluginDefinition['label'], '@bundle' => $bundle, ]); } diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 2f9c6ffd8e3..0a2717dabf3 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -23,24 +23,3 @@ function block_install() { function block_update_last_removed() { return 8003; } - -/** - * Updates the node type visibility condition. - */ -function block_update_9200() { - - $config_factory = \Drupal::configFactory(); - foreach ($config_factory->listAll('block.block.') as $block_config_name) { - $block = $config_factory->getEditable($block_config_name); - - if ($block->get('visibility.node_type')) { - $configuration = $block->get('visibility.node_type'); - $configuration['id'] = 'entity_bundle:node'; - $block->set('visibility.entity_bundle:node', $configuration); - $block->clear('visibility.node_type'); - $block->save(TRUE); - } - - } - -} diff --git a/core/modules/block/block.post_update.php b/core/modules/block/block.post_update.php index 5b4e241d393..2f014e1bcde 100644 --- a/core/modules/block/block.post_update.php +++ b/core/modules/block/block.post_update.php @@ -15,3 +15,24 @@ function block_removed_post_updates() { 'block_post_update_fix_negate_in_conditions' => '9.0.0', ]; } + +/** + * Updates the node type visibility condition. + */ +function block_update_post_update_replace_node_type_condition() { + + $config_factory = \Drupal::configFactory(); + foreach ($config_factory->listAll('block.block.') as $block_config_name) { + $block = $config_factory->getEditable($block_config_name); + + if ($block->get('visibility.node_type')) { + $configuration = $block->get('visibility.node_type'); + $configuration['id'] = 'entity_bundle:node'; + $block->set('visibility.entity_bundle:node', $configuration); + $block->clear('visibility.node_type'); + $block->save(TRUE); + } + + } + +} diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index dad5090416c..0a26fb4f892 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -246,7 +246,8 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for // Don't display the deprecated node type condition unless it has existing // settings. // @todo Make this more generic in - // https://www.drupal.org/project/drupal/issues/2922451. + // https://www.drupal.org/project/drupal/issues/2922451. Also remove + // the node_type specific logic below. if ($condition_id == 'node_type' && !isset($visibility[$condition_id])) { continue; } @@ -262,6 +263,8 @@ protected function buildVisibilityInterface(array $form, FormStateInterface $for } if (isset($form['node_type'])) { + $form['node_type']['#title'] = $this->t('Content types'); + $form['node_type']['bundles']['#title'] = $this->t('Content types'); $form['node_type']['negate']['#type'] = 'value'; $form['node_type']['negate']['#title_display'] = 'invisible'; $form['node_type']['negate']['#value'] = $form['node_type']['negate']['#default_value']; diff --git a/core/modules/node/src/Plugin/Condition/NodeType.php b/core/modules/node/src/Plugin/Condition/NodeType.php index 4b9fd94f9f9..6274a958fe6 100644 --- a/core/modules/node/src/Plugin/Condition/NodeType.php +++ b/core/modules/node/src/Plugin/Condition/NodeType.php @@ -76,7 +76,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $options[$type->id()] = $type->label(); } $form['bundles'] = [ - '#title' => $this->t('Content types'), + '#title' => $this->t('Node types'), '#type' => 'checkboxes', '#options' => $options, '#default_value' => $this->configuration['bundles'], diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleConditionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleConditionTest.php index edd2c9b2378..8f0296e5f4d 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleConditionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityBundleConditionTest.php @@ -12,13 +12,6 @@ */ class EntityBundleConditionTest extends EntityKernelTestBase { - /** - * The condition plugin manager. - * - * @var \Drupal\Core\Condition\ConditionManager - */ - protected $manager; - /** * {@inheritdoc} */ @@ -26,8 +19,6 @@ protected function setUp(): void { parent::setUp(); $this->installEntitySchema('entity_test_with_bundle'); - $this->manager = $this->container->get('plugin.manager.condition'); - // Create the entity bundles required for testing. $bundle = EntityTestBundle::create(['id' => 'page', 'label' => 'page']); $bundle->save(); @@ -53,25 +44,25 @@ public function testConditions() { // Grab the bundle condition and configure it to check against bundle of // 'article' and set the context to the page type entity. /** @var \Drupal\Core\Entity\Plugin\Condition\EntityBundle $condition */ - $condition = $this->manager->createInstance('entity_bundle:entity_test_with_bundle') + $condition = $this->container->get('plugin.manager.condition')->createInstance('entity_bundle:entity_test_with_bundle') ->setConfig('bundles', ['article' => 'article']) ->setContextValue('entity_test_with_bundle', $page); $this->assertFalse($condition->execute(), 'Page type entities fail bundle checks for articles.'); // Check for the proper summary. - $this->assertEquals($condition->summary(), 'Test entity bundle is article'); + $this->assertEquals('Test entity bundle is article', $condition->summary()); $this->assertEquals('entity_test', $condition->getPluginDefinition()['provider']); // Set the bundle check to page. $condition->setConfig('bundles', ['page' => 'page']); $this->assertTrue($condition->execute(), 'Page type entities pass bundle checks for pages'); // Check for the proper summary. - $this->assertEquals($condition->summary(), 'Test entity bundle is page'); + $this->assertEquals('Test entity bundle is page', $condition->summary()); // Set the bundle check to page or article. $condition->setConfig('bundles', ['page' => 'page', 'article' => 'article']); $this->assertTrue($condition->execute(), 'Page type entities pass bundle checks for pages or articles'); // Check for the proper summary. - $this->assertEquals($condition->summary(), 'Test entity bundle is page or article'); + $this->assertEquals('Test entity bundle is page or article', $condition->summary()); // Set the context to the article entity. $condition->setContextValue('entity_test_with_bundle', $article); @@ -87,20 +78,7 @@ public function testConditions() { 'article' => 'article', 'test' => 'test', ]); - $this->assertEquals($condition->summary(), 'Test entity bundle is page, article or test'); - } - - /** - * @group legacy - */ - public function testLegacy() { - $article = EntityTestWithBundle::create(['type' => 'article', 'name' => $this->randomMachineName()]); - $article->save(); - - $this->expectDeprecation('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980'); - // Test Constructor injection. - $condition = $this->manager->createInstance('entity_bundle:entity_test_with_bundle', ['bundles' => ['article' => 'article'], 'context' => ['entity_test_with_bundle' => $article]]); - $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.'); + $this->assertEquals('Test entity bundle is page, article or test', $condition->summary()); } }