andConditionGroup example

$entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]]);
    $this->assertCount(0, $entitiesnew FormattableMarkup('%entity_type: No entity loaded by name translation specifying the translation language.', ['%entity_type' => $entity_type]));
    $entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]$default_langcode_key => 0]);
    $this->assertCount(1, $entitiesnew FormattableMarkup('%entity_type: One entity loaded by name translation and language specifying to look for translations.', ['%entity_type' => $entity_type]));
    $entities = $storage->loadByProperties(['user_id' => $properties[$langcode]['user_id'][0]$default_langcode_key => NULL]);
    $this->assertCount(2, $entitiesnew FormattableMarkup('%entity_type: Two entities loaded by uid without caring about property translatability.', ['%entity_type' => $entity_type]));

    // Test property conditions and orders with multiple languages in the same     // query.     $query = \Drupal::entityQuery($entity_type)->accessCheck(FALSE);
    $group = $query->andConditionGroup()
      ->condition('user_id', $properties[$default_langcode]['user_id'][0], '=', $default_langcode)
      ->condition('name', $properties[$default_langcode]['name'][0], '=', $default_langcode);
    $result = $query
      ->condition($group)
      ->condition('name', $properties[$langcode]['name'][0], '=', $langcode)
      ->execute();
    $this->assertCount(1, $resultnew FormattableMarkup('%entity_type: One entity loaded by name and uid using different language meta conditions.', ['%entity_type' => $entity_type]));

    // Test mixed property and field conditions.     $storage->resetCache($result);
    $entity = $storage->load(reset($result));
    
/** * {@inheritdoc} */
  public function query() {
    $query = $this->select('menu_links', 'ml')
      ->fields('ml')
      // Shortcut set links are migrated by the d7_shortcut migration.       // Shortcuts are not used in Drupal 6.       // @see Drupal\shortcut\Plugin\migrate\source\d7\Shortcut::query()       ->condition('ml.menu_name', 'shortcut-set-%', 'NOT LIKE');
    $and = $query->andConditionGroup()
      ->condition('ml.module', 'menu')
      ->condition('ml.router_path', ['admin/build/menu-customize/%', 'admin/structure/menu/manage/%'], 'NOT IN');
    $condition = $query->orConditionGroup()
      ->condition('ml.customized', 1)
      ->condition($and);
    $query->condition($condition);
    if (isset($this->configuration['menu_name'])) {
      $query->condition('ml.menu_name', (array) $this->configuration['menu_name'], 'IN');
    }
    $query->leftJoin('menu_links', 'pl', '[ml].[plid] = [pl].[mlid]');
    $query->addField('pl', 'link_path', 'parent_link_path');
    
protected function queryConditionData() {
    // ((RED or CIRCLE) or (YELLOW and SQUARE))     $query = $this->nodeStorage->getQuery()->accessCheck(FALSE);

    $or_group = $query->orConditionGroup();

    $nested_or_group = $query->orConditionGroup();
    $nested_or_group->condition('colors', 'red', 'CONTAINS');
    $nested_or_group->condition('shapes', 'circle', 'CONTAINS');
    $or_group->condition($nested_or_group);

    $nested_and_group = $query->andConditionGroup();
    $nested_and_group->condition('colors', 'yellow', 'CONTAINS');
    $nested_and_group->condition('shapes', 'square', 'CONTAINS');
    $nested_and_group->notExists('photo.alt');
    $or_group->condition($nested_and_group);

    $query->condition($or_group);

    return [
      [
        [
          'or-group' => ['group' => ['conjunction' => 'OR']],
          

  protected function buildGroup(QueryInterface $query, EntityConditionGroup $condition_group) {
    // Create a condition group using the original query.     switch ($condition_group->conjunction()) {
      case 'AND':
        $group = $query->andConditionGroup();
        break;

      case 'OR':
        $group = $query->orConditionGroup();
        break;
    }

    // Get all children of the group.     $members = $condition_group->members();

    foreach ($members as $member) {
      
$and_condition_2 = $query->orConditionGroup()
      ->condition('id', 1)
      ->condition('label', $this->entities[3]->label);
    $this->queryResults = $query
      ->condition($and_condition_1)
      ->condition($and_condition_2)
      ->execute();
    $this->assertResults(['1']);

    // NO simple conditions, YES complex conditions, 'OR'.     $query = $this->entityStorage->getQuery('OR');
    $and_condition_1 = $query->andConditionGroup()
      ->condition('id', 1)
      ->condition('label', $this->entities[0]->label);
    $and_condition_2 = $query->andConditionGroup()
      ->condition('id', '2')
      ->condition('label', $this->entities[1]->label);
    $this->queryResults = $query
      ->condition($and_condition_1)
      ->condition($and_condition_2)
      ->execute();
    $this->assertResults(['1', '2']);

    
    $this->queryResults = $this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->condition("$figures.color", 'blue')
      ->condition("$figures.color", 'red')
      ->sort('id')
      ->execute();
    $this->assertResult();

    // But an entity might have a red and a blue figure both.     $query = $this->storage->getQuery()->accessCheck(FALSE);
    $group_blue = $query->andConditionGroup()->condition("$figures.color", 'blue');
    $group_red = $query->andConditionGroup()->condition("$figures.color", 'red');
    $this->queryResults = $query
      ->condition($group_blue)
      ->condition($group_red)
      ->sort('revision_id')
      ->execute();
    // Unit 0 and unit 1, so bits 0 1.     $this->assertResult(3, 7, 11, 15);

    // Do the same test but with IN operator.     $query = $this->storage->getQuery()->accessCheck(FALSE);
    
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()
            

  public function prepare() {
    // Enable all modules in the source except test and example modules, but     // include simpletest.     /** @var \Drupal\Core\Database\Query\SelectInterface $update */
    $update = $this->sourceDatabase->update('system')
      ->fields(['status' => 1])
      ->condition('type', 'module');
    $and = $update->andConditionGroup()
      ->condition('name', '%test%', 'NOT LIKE')
      ->condition('name', '%example%', 'NOT LIKE');
    $conditions = $update->orConditionGroup();
    $conditions->condition($and);
    $conditions->condition('name', 'simpletest');
    $update->condition($conditions);
    $update->execute();

    // Create entries for D8 test modules.     $insert = $this->sourceDatabase->insert('system')
      ->fields([
        


    // Check if any revisions that are about to be published are in a     // non-default revision moderation state.     $query = $this->entityTypeManager->getStorage('content_moderation_state')->getQuery()
      ->allRevisions()
      ->accessCheck(FALSE);
    $query->condition('content_entity_revision_id', $tracked_revision_ids, 'IN');

    $workflow_condition_group = $query->orConditionGroup();
    foreach ($workflow_non_default_states as $workflow_id => $non_default_states) {
      $group = $query->andConditionGroup()
        ->condition('workflow', $workflow_id, '=')
        ->condition('moderation_state', $non_default_states, 'IN');

      $workflow_condition_group->condition($group);
    }
    $query->condition($workflow_condition_group);

    if ($count = $query->count()->execute()) {
      $message = \Drupal::translation()->formatPlural($count, 'The @label workspace can not be published because it contains 1 item in an unpublished moderation state.', 'The @label workspace can not be published because it contains @count items in an unpublished moderation state.', [
        '@label' => $workspace->label(),
      ]);

      
else {
        return AccessResult::neutral();
      }
    }

    // Check the database for potential access grants.     $query = $this->database->select('node_access');
    $query->addExpression('1');
    // Only interested for granting in the current operation.     $query->condition('grant_' . $operation, 1, '>=');
    // Check for grants for this node and the correct langcode.     $nids = $query->andConditionGroup()
      ->condition('nid', $node->id())
      ->condition('langcode', $node->language()->getId());
    // If the node is published, also take the default grant into account. The     // default is saved with a node ID of 0.     $status = $node->isPublished();
    if ($status) {
      $nids = $query->orConditionGroup()
        ->condition($nids)
        ->condition('nid', 0);
    }
    $query->condition($nids);
    
Home | Imprint | This part of the site doesn't use cookies.