You are here

protected function TestSelection::buildEntityQuery in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection::buildEntityQuery()
  2. 9 core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection::buildEntityQuery()

Builds an EntityQuery to get referenceable entities.

Parameters

string|null $match: (Optional) Text to match the label against. Defaults to NULL.

string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".

Return value

\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.

Overrides DefaultSelection::buildEntityQuery

File

core/modules/block_content/tests/modules/block_content_test/src/Plugin/EntityReferenceSelection/TestSelection.php, line 42

Class

TestSelection
Test EntityReferenceSelection with conditions on the 'reusable' field.

Namespace

Drupal\block_content_test\Plugin\EntityReferenceSelection

Code

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;
}