You are here

protected function LingotekManagementForm::getFilters in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  2. 4.0.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  3. 3.0.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  4. 3.1.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  5. 3.2.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  6. 3.3.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  7. 3.5.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  8. 3.6.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  9. 3.7.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()
  10. 3.8.x src/Form/LingotekManagementForm.php \Drupal\lingotek\Form\LingotekManagementForm::getFilters()

Gets the filters for rendering.

Return value

array A form array.

Overrides LingotekManagementFormBase::getFilters

File

src/Form/LingotekManagementForm.php, line 249

Class

LingotekManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

protected function getFilters() {
  $filters = [];
  $temp_store = $this->tempStoreFactory
    ->get($this
    ->getTempStorageFilterKey());
  $entity_type = $this->entityTypeManager
    ->getDefinition($this->entityTypeId);
  $properties = $this->entityFieldManager
    ->getBaseFieldDefinitions($this->entityTypeId);
  $has_bundles = $entity_type
    ->get('bundle_entity_type') != 'bundle';
  $groupsExists = $this->moduleHandler
    ->moduleExists('group') && $this->entityTypeId === 'node';
  $labelFilter = $temp_store
    ->get('label');
  $bundleFilter = $temp_store
    ->get('bundle');
  $groupFilter = $groupsExists ? $temp_store
    ->get('group') : NULL;
  $jobFilter = $temp_store
    ->get('job');
  if ($entity_type
    ->getKey('label')) {
    $filters['label'] = [
      '#type' => 'textfield',
      '#title' => $has_bundles && $entity_type
        ->hasKey('label') ? $properties[$entity_type
        ->getKey('label')]
        ->getLabel() : $entity_type
        ->getLabel(),
      '#placeholder' => $this
        ->t('Filter by @title', [
        '@title' => $entity_type
          ->getBundleLabel(),
      ]),
      '#default_value' => $labelFilter,
      '#attributes' => [
        'class' => [
          'form-item',
        ],
      ],
    ];
  }
  if ($has_bundles) {
    $filters['bundle'] = [
      '#type' => 'select',
      '#title' => $entity_type
        ->getBundleLabel(),
      '#options' => [
        '' => $this
          ->t('All'),
      ] + $this
        ->getAllBundles(),
      '#default_value' => $bundleFilter,
      '#attributes' => [
        'class' => [
          'form-item',
        ],
      ],
      '#multiple' => TRUE,
    ];
  }
  if ($groupsExists) {
    $filters['group'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Group'),
      '#options' => [
        '' => $this
          ->t('All'),
      ] + $this
        ->getAllGroups(),
      '#default_value' => $groupFilter,
      '#attributes' => [
        'class' => [
          'form-item',
        ],
      ],
    ];
  }
  $filters['job'] = [
    '#type' => 'lingotek_job_id',
    '#title' => $this
      ->t('Job ID'),
    '#default_value' => $jobFilter,
    '#attributes' => [
      'class' => [
        'form-item',
      ],
    ],
  ];
  return $filters;
}