entityQueryAlter example

/** @var \Drupal\user\UserInterface $user */
        return $user->isActive();
      });
    }
    return $entities;
  }

  /** * {@inheritdoc} */
  public function entityQueryAlter(SelectInterface $query) {
    parent::entityQueryAlter($query);

    // Bail out early if we do not need to match the Anonymous user.     if (!$this->getConfiguration()['include_anonymous']) {
      return;
    }

    if ($this->currentUser->hasPermission('administer users')) {
      // In addition, if the user is administrator, we need to make sure to       // match the anonymous user, that doesn't actually have a name in the       // database.       $conditions = &$query->conditions();
      
->condition($entity_type->getKey('id')$ids, 'IN')
        ->execute();
    }

    return $result;
  }

  /** * {@inheritdoc} */
  public function entityQueryAlter(SelectInterface $query) {
    parent::entityQueryAlter($query);

    $tables = $query->getTables();
    $data_table = 'comment_field_data';
    if (!isset($tables['comment_field_data']['alias'])) {
      // If no conditions join against the comment data table, it should be       // joined manually to allow node access processing.       $query->innerJoin($data_table, NULL, "[base_table].[cid] = [$data_table].[cid] AND [$data_table].[default_langcode] = 1");
    }

    // Historically, comments were always linked to 'node' entities, but that is     // no longer the case, as the 'node' module might not even be enabled.
Home | Imprint | This part of the site doesn't use cookies.