class TestSelection
Same name in other branches
- 9 core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection
- 8.9.x core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection
- 8.9.x core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php \Drupal\Tests\Core\EntityReferenceSelection\TestSelection
- 11.x core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection
Test EntityReferenceSelection with conditions on the 'reusable' field.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface, \Drupal\Component\Plugin\ConfigurableInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection extends \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface
- class \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection extends \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
- class \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection extends \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface
- class \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface, \Drupal\Component\Plugin\ConfigurableInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of TestSelection
1 file declares its use of TestSelection
- BlockContentEntityReferenceSelectionTest.php in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentEntityReferenceSelectionTest.php
File
-
core/
modules/ block_content/ tests/ modules/ block_content_test/ src/ Plugin/ EntityReferenceSelection/ TestSelection.php, line 10
Namespace
Drupal\block_content_test\Plugin\EntityReferenceSelectionView source
class TestSelection extends DefaultSelection {
/**
* The condition type.
*
* @var string
*/
protected $conditionType;
/**
* Whether to set the condition for reusable or non-reusable blocks.
*
* @var bool
*/
protected $isReusable;
/**
* Sets the test mode.
*
* @param string $condition_type
* The condition type.
* @param bool $is_reusable
* Whether to set the condition for reusable or non-reusable blocks.
*/
public function setTestMode($condition_type = NULL, $is_reusable = NULL) {
$this->conditionType = $condition_type;
$this->isReusable = $is_reusable;
}
/**
* {@inheritdoc}
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if ($this->conditionType) {
/** @var \Drupal\Core\Database\Query\ConditionInterface $add_condition */
$add_condition = NULL;
switch ($this->conditionType) {
case 'base':
$add_condition = $query;
break;
case 'group':
$group = $query->andConditionGroup()
->exists('type');
$add_condition = $group;
$query->condition($group);
break;
case "nested_group":
$query->exists('type');
$sub_group = $query->andConditionGroup()
->exists('type');
$add_condition = $sub_group;
$group = $query->andConditionGroup()
->exists('type')
->condition($sub_group);
$query->condition($group);
break;
}
if ($this->isReusable) {
$add_condition->condition('reusable', 1);
}
else {
$add_condition->condition('reusable', 0);
}
}
return $query;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.