You are here

protected function YamlFormEntityListBuilder::getQuery in YAML Form 8

Get the base entity query filtered by form and search.

Parameters

string $keys: (optional) Search key.

string $state: (optional) Form state. Can be 'open' or 'closed'.

Return value

\Drupal\Core\Entity\Query\QueryInterface An entity query.

File

src/YamlFormEntityListBuilder.php, line 279

Class

YamlFormEntityListBuilder
Defines a class to build a listing of form entities.

Namespace

Drupal\yamlform

Code

protected function getQuery($keys = '', $state = '') {
  $query = $this
    ->getStorage()
    ->getQuery();

  // Filter by key(word).
  if ($keys) {
    $or = $query
      ->orConditionGroup()
      ->condition('title', $this->keys, 'CONTAINS')
      ->condition('description', $this->keys, 'CONTAINS')
      ->condition('elements', $this->keys, 'CONTAINS');
    $query
      ->condition($or);
  }

  // Filter by (form) state.
  if ($state == self::STATE_OPEN || $state == self::STATE_CLOSED) {
    $query
      ->condition('status', $state == self::STATE_OPEN ? TRUE : FALSE);
  }

  // Filter out templates if the yamlform_template.module is enabled.
  if ($this
    ->moduleHandler()
    ->moduleExists('yamlform_templates')) {
    $query
      ->condition('template', FALSE);
  }
  return $query;
}