Commit 4de7ad96 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher Committed by Joël Pittet
Browse files

Issue #2857279 by Berdir, manuel.adan, malcomio: Duplicate node type...

Issue #2857279 by Berdir, manuel.adan, malcomio: Duplicate node type visibility condition in block settings
parent 42353cf4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
<?php

use Drupal\Core\Entity\Plugin\Condition\EntityBundle as CoreEntityBundle;
use Drupal\ctools\Plugin\Condition\EntityBundle;

/**
 * @file
 * Provides utility and helper APIs for Drupal developers and site builders.
@@ -91,6 +94,15 @@ function ctools_condition_info_alter(&$definitions) {
  if (isset($definitions['node_type']) && $definitions['node_type']['class'] == 'Drupal\node\Plugin\Condition\NodeType') {
    $definitions['node_type']['class'] = 'Drupal\ctools\Plugin\Condition\NodeType';
  }

  // Replace all generic entity bundle conditions classes if they are unaltered,
  // these exist in Drupal 9.3+.
  foreach ($definitions as $id => $definition) {
    if (strpos($id, 'entity_bundle:') === 0 && $definition['class'] == CoreEntityBundle::class) {
      $definitions[$id]['class'] = EntityBundle::class;
    }
  }

}


+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\ctools\ConstraintConditionInterface;
use \Drupal\Core\Entity\Plugin\Condition\EntityBundle as CoreEntityBundle;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
+7 −0
Original line number Diff line number Diff line
@@ -13,6 +13,13 @@ class EntityBundle extends EntityDeriverBase {
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // Do not define any derivatives on Drupal 9.3+, instead, replace the core
    // class in ctools_condition_info_alter().
    if (\version_compare(\Drupal::VERSION, '9.3', '>')) {
      return [];
    }

    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if ($entity_type->hasKey('bundle')) {
        $this->derivatives[$entity_type_id] = $base_plugin_definition;