buildEntityQuery example



    $form += parent::buildConfigurationForm($form$form_state);

    return $form;
  }

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);

    $configuration = $this->getConfiguration();

    // Filter out the Anonymous user if the selection handler is configured to     // exclude it.     if (!$configuration['include_anonymous']) {
      $query->condition('uid', 0, '<>');
    }

    // The user entity doesn't have a label column.     if (isset($match)) {
      
public static function elementValidateFilter(&$element, FormStateInterface $form_state) {
    $element['#value'] = array_filter($element['#value']);
    $form_state->setValueForElement($element$element['#value']);
  }

  /** * {@inheritdoc} */
  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $target_type = $this->getConfiguration()['target_type'];

    $query = $this->buildEntityQuery($match$match_operator);
    if ($limit > 0) {
      $query->range(0, $limit);
    }

    $result = $query->execute();

    if (empty($result)) {
      return [];
    }

    $options = [];
    

class AllExceptHostEntity extends DefaultSelection {

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    if ($entity = $this->configuration['entity']) {
      $target_type = $this->configuration['target_type'];
      $entity_type = $this->entityTypeManager->getDefinition($target_type);
      $query->condition($entity_type->getKey('id')$entity->id(), '<>');
    }

    return $query;
  }

}
$referenceable_entities = $this->getReferenceableEntities($match$match_operator, 0);
    foreach ($referenceable_entities as $entities) {
      $total += count($entities);
    }
    return $total;
  }

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);

    // Adding the 'taxonomy_term_access' tag is sadly insufficient for terms:     // core requires us to also know about the concept of 'published' and     // 'unpublished'.     if (!$this->currentUser->hasPermission('administer taxonomy')) {
      $query->condition('status', 1);
    }
    return $query;
  }

  /** * {@inheritdoc} */

class FileSelection extends DefaultSelection {

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);
    // Allow referencing :     // - files with status "permanent"     // - or files uploaded by the current user (since newly uploaded files only     // become "permanent" after the containing entity gets validated and     // saved.)     $query->condition($query->orConditionGroup()
      ->condition('status', FileInterface::STATUS_PERMANENT)
      ->condition('uid', $this->currentUser->id()));
    return $query;
  }

  

class MediaSelection extends DefaultSelection {

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);

    // Ensure that users with insufficient permission cannot see unpublished     // entities.     if (!$this->currentUser->hasPermission('administer media')) {
      $query->condition('status', 1);
    }
    return $query;
  }

  /** * {@inheritdoc} */

  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');
          

class CommentSelection extends DefaultSelection {

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);

    // Adding the 'comment_access' tag is sadly insufficient for comments:     // core requires us to also know about the concept of 'published' and     // 'unpublished'.     if (!$this->currentUser->hasPermission('administer comments')) {
      $query->condition('status', CommentInterface::PUBLISHED);
    }
    return $query;
  }

  /** * {@inheritdoc} */

class NodeSelection extends DefaultSelection {

  /** * {@inheritdoc} */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match$match_operator);
    // Adding the 'node_access' tag is sadly insufficient for nodes: core     // requires us to also know about the concept of 'published' and     // 'unpublished'. We need to do that as long as there are no access control     // modules in use on the site. As long as one access control module is there,     // it is supposed to handle this check.     if (!$this->currentUser->hasPermission('bypass node access') && !$this->moduleHandler->hasImplementations('node_grants')) {
      $query->condition('status', NodeInterface::PUBLISHED);
    }
    return $query;
  }

  
Home | Imprint | This part of the site doesn't use cookies.