You are here

class LingotekManagementForm in Lingotek Translation 3.1.x

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

Form for bulk management of content.

Hierarchy

Expanded class hierarchy of LingotekManagementForm

1 file declares its use of LingotekManagementForm
LingotekManagementFormTest.php in tests/src/Unit/Form/LingotekManagementFormTest.php

File

src/Form/LingotekManagementForm.php, line 15

Namespace

Drupal\lingotek\Form
View source
class LingotekManagementForm extends LingotekManagementFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'lingotek_management';
  }

  /**
   * {@inheritdoc}
   */
  protected function getHeaders() {
    $entity_type = $this->entityTypeManager
      ->getDefinition($this->entityTypeId);
    $properties = $this->entityFieldManager
      ->getBaseFieldDefinitions($this->entityTypeId);
    $has_bundles = $entity_type
      ->get('bundle_entity_type') != 'bundle';
    if ($has_bundles) {
      $headers['bundle'] = $entity_type
        ->getBundleLabel();
    }
    $headers += [
      'title' => $has_bundles && $entity_type
        ->hasKey('label') ? $properties[$entity_type
        ->getKey('label')]
        ->getLabel() : $entity_type
        ->getLabel(),
      'source' => $this
        ->t('Source'),
      'translations' => $this
        ->t('Translations'),
      'profile' => $this
        ->t('Profile'),
      'job_id' => $this
        ->t('Job ID'),
    ];
    return $headers;
  }

  /**
   * {@inheritdoc}
   */
  protected function getFilteredEntities() {
    $items_per_page = $this
      ->getItemsPerPage();

    /** @var PrivateTempStore $temp_store */
    $temp_store = $this->tempStoreFactory
      ->get($this
      ->getTempStorageFilterKey());

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    $entity_type = $this->entityTypeManager
      ->getDefinition($this->entityTypeId);

    /** @var \Drupal\Core\Database\Query\SelectInterface $query */
    $query = $this->connection
      ->select($entity_type
      ->getBaseTable(), 'entity_table')
      ->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender');
    $query
      ->fields('entity_table', [
      $entity_type
        ->getKey('id'),
    ]);
    $union = NULL;
    $union2 = NULL;
    $has_bundles = $entity_type
      ->get('bundle_entity_type') != 'bundle';
    $groupsExists = $this->moduleHandler
      ->moduleExists('group') && $this->entityTypeId === 'node';

    // Filter results
    // Default options
    $labelFilter = $temp_store
      ->get('label');
    $bundleFilter = $temp_store
      ->get('bundle');
    $groupFilter = $groupsExists ? $temp_store
      ->get('group') : NULL;
    $jobFilter = $temp_store
      ->get('job');

    // Advanced options
    $documentIdFilter = $temp_store
      ->get('document_id');
    $entityIdFilter = $temp_store
      ->get('entity_id');
    $sourceLanguageFilter = $temp_store
      ->get('source_language');
    $sourceStatusFilter = $temp_store
      ->get('source_status');
    $targetStatusFilter = $temp_store
      ->get('target_status');
    $profileFilter = $temp_store
      ->get('profile');
    if ($sourceStatusFilter) {
      if ($sourceStatusFilter === 'UPLOAD_NEEDED') {

        // We consider that "Upload Needed" includes those never uploaded or
        // disassociated, edited, or with error on last upload.
        $needingUploadStatuses = [
          Lingotek::STATUS_EDITED,
          Lingotek::STATUS_REQUEST,
          Lingotek::STATUS_CANCELLED,
          Lingotek::STATUS_ERROR,
        ];
        $metadata_type = $this->entityTypeManager
          ->getDefinition('lingotek_content_metadata');
        $query
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata_source', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata_source.content_entity_id AND metadata_source.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $query
          ->innerJoin('lingotek_content_metadata__translation_status', 'translation_status', 'metadata_source.id = translation_status.entity_id AND translation_status.translation_status_language = entity_table.' . $entity_type
          ->getKey('langcode'));
        $query
          ->condition('translation_status.translation_status_value', $needingUploadStatuses, 'IN');

        // No metadata.
        $no_metadata_query = $this->connection
          ->select($metadata_type
          ->getBaseTable(), 'mt');
        $no_metadata_query
          ->fields('mt', [
          $metadata_type
            ->getKey('id'),
        ]);
        $no_metadata_query
          ->where('entity_table.' . $entity_type
          ->getKey('id') . ' = mt.content_entity_id');
        $no_metadata_query
          ->condition('mt.content_entity_type_id', $entity_type
          ->id());
        $union = $this->connection
          ->select($entity_type
          ->getBaseTable(), 'entity_table');
        $union
          ->fields('entity_table', [
          $entity_type
            ->getKey('id'),
        ]);
        $union
          ->condition('entity_table.' . $entity_type
          ->getKey('langcode'), LanguageInterface::LANGCODE_NOT_SPECIFIED, '!=');
        $union
          ->notExists($no_metadata_query);

        // No target statuses.
        $no_statuses_query = $this->connection
          ->select('lingotek_content_metadata__translation_status', 'tst');
        $no_statuses_query
          ->fields('tst', [
          'entity_id',
        ]);
        $no_statuses_query
          ->where('mt2.' . $metadata_type
          ->getKey('id') . ' = tst.entity_id');
        $union2 = $this->connection
          ->select($entity_type
          ->getBaseTable(), 'entity_table');
        $union2
          ->innerJoin($metadata_type
          ->getBaseTable(), 'mt2', 'entity_table.' . $entity_type
          ->getKey('id') . '= mt2.content_entity_id AND mt2.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union2
          ->fields('entity_table', [
          $entity_type
            ->getKey('id'),
        ]);
        $union2
          ->condition('entity_table.' . $entity_type
          ->getKey('langcode'), LanguageInterface::LANGCODE_NOT_SPECIFIED, '!=');
        $union2
          ->notExists($no_statuses_query);
        $query
          ->union($union);
        $query
          ->union($union2);
      }
      else {
        $metadata_type = $this->entityTypeManager
          ->getDefinition('lingotek_content_metadata');
        $query
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata_source', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata_source.content_entity_id AND metadata_source.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $query
          ->innerJoin('lingotek_content_metadata__translation_status', 'translation_status', 'metadata_source.id = translation_status.entity_id AND translation_status.translation_status_language = entity_table.' . $entity_type
          ->getKey('langcode'));
        $query
          ->condition('translation_status.translation_status_value', $sourceStatusFilter);
      }
    }

    // Default queries
    if ($has_bundles && $bundleFilter) {
      if (!in_array("", $bundleFilter, TRUE)) {
        $query
          ->condition('entity_table.' . $entity_type
          ->getKey('bundle'), $bundleFilter, 'IN');
        if ($union !== NULL) {
          $union
            ->condition('entity_table.' . $entity_type
            ->getKey('bundle'), $bundleFilter, 'IN');
        }
        if ($union2 !== NULL) {
          $union2
            ->condition('entity_table.' . $entity_type
            ->getKey('bundle'), $bundleFilter, 'IN');
        }
      }
    }
    if ($labelFilter) {
      $labelKey = $entity_type
        ->getKey('label');
      if ($labelKey) {
        $query
          ->innerJoin($entity_type
          ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
          ->getKey('id') . '= entity_data.' . $entity_type
          ->getKey('id'));
        $query
          ->condition('entity_data.' . $labelKey, '%' . $labelFilter . '%', 'LIKE');
        if ($union !== NULL) {
          $union
            ->innerJoin($entity_type
            ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
            ->getKey('id') . '= entity_data.' . $entity_type
            ->getKey('id'));
          $union
            ->condition('entity_data.' . $labelKey, '%' . $labelFilter . '%', 'LIKE');
        }
        if ($union2 !== NULL) {
          $union2
            ->innerJoin($entity_type
            ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
            ->getKey('id') . '= entity_data.' . $entity_type
            ->getKey('id'));
          $union2
            ->condition('entity_data.' . $labelKey, '%' . $labelFilter . '%', 'LIKE');
        }
      }
    }
    if ($groupFilter) {

      /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $groupContentEnablers */
      $groupType = Group::load($groupFilter)
        ->getGroupType();
      $groupContentEnablers = \Drupal::service('plugin.manager.group_content_enabler');
      $definitions = $groupContentEnablers
        ->getDefinitions();
      $definitions = array_filter($definitions, function ($definition) {
        return $definition['entity_type_id'] === 'node';
      });
      $valid_values = [];
      foreach ($definitions as $node_definition) {
        $valid_values[] = $groupType
          ->id() . '-' . $node_definition['id'] . '-' . $node_definition['entity_bundle'];
      }
      $query
        ->innerJoin('group_content_field_data', 'group_content', 'entity_table.' . $entity_type
        ->getKey('id') . '= group_content.entity_id');
      $query
        ->condition('group_content.gid', $groupFilter);
      $query
        ->condition('group_content.type', $valid_values, 'IN');
      if ($union !== NULL) {
        $union
          ->innerJoin('group_content_field_data', 'group_content', 'entity_table.' . $entity_type
          ->getKey('id') . '= group_content.entity_id');
        $union
          ->condition('group_content.gid', $groupFilter);
        $union
          ->condition('group_content.type', $valid_values, 'IN');
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin('group_content_field_data', 'group_content', 'entity_table.' . $entity_type
          ->getKey('id') . '= group_content.entity_id');
        $union2
          ->condition('group_content.gid', $groupFilter);
        $union2
          ->condition('group_content.type', $valid_values, 'IN');
      }
    }
    if ($jobFilter) {

      /** @var \Drupal\Core\Entity\EntityTypeInterface $metadata_type */
      $metadata_type = $this->entityTypeManager
        ->getDefinition('lingotek_content_metadata');
      $query
        ->innerJoin($metadata_type
        ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
        ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
        ->id() . '\'');
      $query
        ->condition('metadata.job_id', '%' . $jobFilter . '%', 'LIKE');
      if ($union !== NULL) {
        $union
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union
          ->condition('metadata.job_id', '%' . $jobFilter . '%', 'LIKE');
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union2
          ->condition('metadata.job_id', '%' . $jobFilter . '%', 'LIKE');
      }
    }

    // Advanced queries
    if ($documentIdFilter) {
      $documentIdArray = explode(',', $documentIdFilter);
      array_walk($documentIdArray, function (&$value) {
        $value = trim($value);
      });
      $documentIdOperator = count($documentIdArray) > 1 ? 'IN' : 'LIKE';
      $documentIdValue = count($documentIdArray) > 1 ? $documentIdArray : '%' . $documentIdFilter . '%';
      $metadata_type = $this->entityTypeManager
        ->getDefinition('lingotek_content_metadata');
      $query
        ->innerJoin($metadata_type
        ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
        ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
        ->id() . '\'');
      $query
        ->condition('metadata.document_id', $documentIdValue, $documentIdOperator);
      if ($union !== NULL) {
        $union
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union
          ->condition('metadata.document_id', $documentIdValue, $documentIdOperator);
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union2
          ->condition('metadata.document_id', $documentIdValue, $documentIdOperator);
      }
    }
    if ($entityIdFilter) {
      $entityIdArray = explode(',', $entityIdFilter);
      array_walk($entityIdArray, function (&$value) {
        $value = trim($value);
      });
      $entityIdOperator = count($entityIdArray) > 1 ? 'IN' : '=';
      $entityIdValue = count($entityIdArray) > 1 ? $entityIdArray : $entityIdFilter;
      $query
        ->innerJoin($entity_type
        ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
        ->getKey('id') . '= entity_data.' . $entity_type
        ->getKey('id'));
      $query
        ->condition('entity_table.' . $entity_type
        ->getKey('id'), $entityIdValue, $entityIdOperator);
      if ($union !== NULL) {
        $union
          ->innerJoin($entity_type
          ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
          ->getKey('id') . '= entity_data.' . $entity_type
          ->getKey('id'));
        $union
          ->condition('entity_table.' . $entity_type
          ->getKey('id'), $entityIdValue, $entityIdOperator);
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin($entity_type
          ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
          ->getKey('id') . '= entity_data.' . $entity_type
          ->getKey('id'));
        $union2
          ->condition('entity_table.' . $entity_type
          ->getKey('id'), $entityIdValue, $entityIdOperator);
      }
    }
    if ($profileFilter) {
      $profileOptions = $this->lingotekConfiguration
        ->getProfileOptions();
      if (is_string($profileFilter)) {
        $profileFilter = [
          $profileFilter,
        ];
      }
      if (!in_array("", $profileFilter, TRUE)) {
        $metadata_type = $this->entityTypeManager
          ->getDefinition('lingotek_content_metadata');
        $query
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $query
          ->condition('metadata.profile', $profileFilter, 'IN');
        if ($union !== NULL) {
          $union
            ->innerJoin($metadata_type
            ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
            ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
            ->id() . '\'');
          $union
            ->condition('metadata.profile', $profileFilter, 'IN');
        }
        if ($union2 !== NULL) {
          $union2
            ->innerJoin($metadata_type
            ->getBaseTable(), 'metadata', 'entity_table.' . $entity_type
            ->getKey('id') . '= metadata.content_entity_id AND metadata.content_entity_type_id = \'' . $entity_type
            ->id() . '\'');
          $union2
            ->condition('metadata.profile', $profileFilter, 'IN');
        }
      }
    }
    if ($sourceLanguageFilter) {
      $query
        ->innerJoin($entity_type
        ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
        ->getKey('id') . '= entity_data.' . $entity_type
        ->getKey('id'));
      $query
        ->condition('entity_table.' . $entity_type
        ->getKey('langcode'), $sourceLanguageFilter);
      $query
        ->condition('entity_data.default_langcode', 1);
      if ($union !== NULL) {
        $union
          ->innerJoin($entity_type
          ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
          ->getKey('id') . '= entity_data.' . $entity_type
          ->getKey('id'));
        $union
          ->condition('entity_table.' . $entity_type
          ->getKey('langcode'), $sourceLanguageFilter);
        $union
          ->condition('entity_data.default_langcode', 1);
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin($entity_type
          ->getDataTable(), 'entity_data', 'entity_table.' . $entity_type
          ->getKey('id') . '= entity_data.' . $entity_type
          ->getKey('id'));
        $union2
          ->condition('entity_table.' . $entity_type
          ->getKey('langcode'), $sourceLanguageFilter);
        $union2
          ->condition('entity_data.default_langcode', 1);
      }
    }

    // We don't want items with language undefined.
    $query
      ->condition('entity_table.' . $entity_type
      ->getKey('langcode'), LanguageInterface::LANGCODE_NOT_SPECIFIED, '!=');
    if ($targetStatusFilter) {
      $metadata_type = $this->entityTypeManager
        ->getDefinition('lingotek_content_metadata');
      $query
        ->innerJoin($metadata_type
        ->getBaseTable(), 'metadata_target', 'entity_table.' . $entity_type
        ->getKey('id') . '= metadata_target.content_entity_id AND metadata_target.content_entity_type_id = \'' . $entity_type
        ->id() . '\'');
      $query
        ->innerJoin('lingotek_content_metadata__translation_status', 'translation_target_status', 'metadata_target.id = translation_target_status.entity_id AND translation_target_status.translation_status_language <> entity_table.' . $entity_type
        ->getKey('langcode'));
      $query
        ->condition('translation_target_status.translation_status_value', $targetStatusFilter);
      if ($union !== NULL) {
        $union
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata_target', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata_target.content_entity_id AND metadata_target.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union
          ->innerJoin('lingotek_content_metadata__translation_status', 'translation_target_status', 'metadata_target.id = translation_target_status.entity_id AND translation_target_status.translation_status_language <> entity_table.' . $entity_type
          ->getKey('langcode'));
        $union
          ->condition('translation_target_status.translation_status_value', $targetStatusFilter);
      }
      if ($union2 !== NULL) {
        $union2
          ->innerJoin($metadata_type
          ->getBaseTable(), 'metadata_target', 'entity_table.' . $entity_type
          ->getKey('id') . '= metadata_target.content_entity_id AND metadata_target.content_entity_type_id = \'' . $entity_type
          ->id() . '\'');
        $union2
          ->innerJoin('lingotek_content_metadata__translation_status', 'translation_target_status', 'metadata_target.id = translation_target_status.entity_id AND translation_target_status.translation_status_language <> entity_table.' . $entity_type
          ->getKey('langcode'));
        $union2
          ->condition('translation_target_status.translation_status_value', $targetStatusFilter);
      }
    }
    $ids = $query
      ->limit($items_per_page)
      ->execute()
      ->fetchCol(0);
    $entities = $this->entityTypeManager
      ->getStorage($this->entityTypeId)
      ->loadMultiple($ids);
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  protected function getSelectedEntities($values) {
    return $this->entityTypeManager
      ->getStorage($this->entityTypeId)
      ->loadMultiple($values);
  }

  /**
   * {@inheritdoc}
   */
  protected function getRows($entity_list) {
    $rows = [];
    foreach ($entity_list as $entity_id => $entity) {
      $rows[$entity_id] = $this
        ->getRow($entity);
    }
    return $rows;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected function getPager() {
    $items_per_page = $this
      ->getItemsPerPage();
    return [
      '#type' => 'select',
      '#title' => $this
        ->t('Results per page:'),
      '#options' => [
        10 => 10,
        25 => 25,
        50 => 50,
        100 => 100,
        250 => 250,
        500 => 500,
      ],
      '#default_value' => $items_per_page,
      '#weight' => 60,
      '#ajax' => [
        'callback' => [
          $this,
          'itemsPerPageCallback',
        ],
        'event' => 'change',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function itemsPerPageCallback(array &$form, FormStateInterface $form_state) {
    $ajax_response = new AjaxResponse();
    $this
      ->setItemsPerPage($form_state
      ->getValue('items_per_page'));
    $ajax_response
      ->addCommand(new InvokeCommand('#lingotek-management', 'submit'));
    return $ajax_response;
  }

  /**
   * {@inheritdoc}
   */
  protected function getTempStorageFilterKey() {
    return 'lingotek.management.filter.' . $this->entityTypeId;
  }

  /**
   * {@inheritdoc}
   */
  protected function getFilterKeys() {
    $groupsExists = $this->moduleHandler
      ->moduleExists('group') && $this->entityTypeId === 'node';

    // We need specific identifiers for default and advanced filters since the advanced filters bundle is unique.
    $filtersKeys = [
      [
        'wrapper',
        'label',
      ],
      [
        'wrapper',
        'bundle',
      ],
      [
        'wrapper',
        'job',
      ],
      [
        'advanced_options',
        'document_id',
      ],
      [
        'advanced_options',
        'entity_id',
      ],
      [
        'advanced_options',
        'profile',
      ],
      [
        'advanced_options',
        'source_language',
      ],
      [
        'advanced_options',
        'source_status',
      ],
      [
        'advanced_options',
        'target_status',
      ],
    ];
    if ($groupsExists) {
      $filtersKeys[] = [
        'wrapper',
        'group',
      ];
    }
    return $filtersKeys;
  }
  public function getEntityTypeId() {
    return $this->entityTypeId;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LingotekManagementForm::getEntityTypeId public function
LingotekManagementForm::getFilteredEntities protected function Gets the entities that needs to be displayed based on the current filters. Overrides LingotekManagementFormBase::getFilteredEntities
LingotekManagementForm::getFilterKeys protected function Gets the filter keys so we can persist or clear filtering options. Overrides LingotekManagementFormBase::getFilterKeys
LingotekManagementForm::getFilters protected function Gets the filters for rendering. Overrides LingotekManagementFormBase::getFilters
LingotekManagementForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
LingotekManagementForm::getHeaders protected function Overrides LingotekManagementFormBase::getHeaders
LingotekManagementForm::getPager protected function Gets the pager. Overrides LingotekManagementFormBase::getPager
LingotekManagementForm::getRows protected function Gets the rows for rendering based on the passed entity list. Overrides LingotekManagementFormBase::getRows
LingotekManagementForm::getSelectedEntities protected function Load the entities corresponding with the given identifiers. Overrides LingotekManagementFormBase::getSelectedEntities
LingotekManagementForm::getTempStorageFilterKey protected function Gets the key used for persisting filtering options in the temp storage. Overrides LingotekManagementFormBase::getTempStorageFilterKey
LingotekManagementForm::itemsPerPageCallback public function
LingotekManagementFormBase::$connection protected property The connection object on which to run queries.
LingotekManagementFormBase::$contentTranslationManager protected property The content translation manager.
LingotekManagementFormBase::$entityFieldManager protected property The entity field manager.
LingotekManagementFormBase::$entityTypeBundleInfo protected property The entity type bundle info.
LingotekManagementFormBase::$entityTypeId protected property The entity type id.
LingotekManagementFormBase::$entityTypeManager protected property The entity manager.
LingotekManagementFormBase::$languageLocaleMapper protected property The language-locale mapper.
LingotekManagementFormBase::$languageManager protected property The language manager.
LingotekManagementFormBase::$lingotekConfiguration protected property The Lingotek configuration service.
LingotekManagementFormBase::$moduleHandler protected property The module handler.
LingotekManagementFormBase::$state protected property The state key value store.
LingotekManagementFormBase::$translationService protected property The Lingotek content translation service.
LingotekManagementFormBase::batchFinished public function Batch callback called when the batch finishes.
LingotekManagementFormBase::buildForm public function Form constructor. Overrides FormInterface::buildForm 2
LingotekManagementFormBase::cancel public function Cancel the content from Lingotek.
LingotekManagementFormBase::cancelTarget public function Cancel the content from Lingotek.
LingotekManagementFormBase::canHaveDeleteBulkOptions protected function Check if we can delete content in bulk based on the entity definition. 2
LingotekManagementFormBase::canHaveDeleteTranslationBulkOptions protected function Check if we can delete translation in bulk based on the entity definition. 2
LingotekManagementFormBase::changeProfile public function Change Translation Profile.
LingotekManagementFormBase::checkDocumentUploadStatus public function Check document upload status for a given content.
LingotekManagementFormBase::checkTranslationStatus public function Checks translation status for a given content in a given language.
LingotekManagementFormBase::checkTranslationStatuses public function Checks all translations statuses for a given content.
LingotekManagementFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 2
LingotekManagementFormBase::createBatch protected function Performs an operation to several values in a batch.
LingotekManagementFormBase::createCancelBatch protected function Create and set a cancellation batch.
LingotekManagementFormBase::createChangeProfileBatch protected function Create and set a profile change batch.
LingotekManagementFormBase::createDebugExportBatch protected function Create and set an export batch.
LingotekManagementFormBase::createDownloadBatch protected function Create and set a request target and download batch for all languages.
LingotekManagementFormBase::createLanguageDownloadBatch protected function Create and set a request target and download batch for a given language.
LingotekManagementFormBase::createLanguageRequestTranslationBatch protected function Create and set a request translations batch for all languages.
LingotekManagementFormBase::createLanguageTranslationCheckStatusBatch protected function Create and set a check translation status batch for a given language.
LingotekManagementFormBase::createRequestTranslationsBatch protected function Create and set a request translations batch for all languages.
LingotekManagementFormBase::createTargetCancelBatch protected function Create and set a target cancellation batch.
LingotekManagementFormBase::createTranslationCheckStatusBatch protected function Create and set a check translation status batch for all languages.
LingotekManagementFormBase::createUploadBatch protected function Create and set an upload batch.
LingotekManagementFormBase::createUploadCheckStatusBatch protected function Create and set a check upload status batch.
LingotekManagementFormBase::debugExport public function Export source for debugging purposes.
LingotekManagementFormBase::debugExportFinished public function Batch callback called when the debug export batch finishes.
LingotekManagementFormBase::downloadTranslation public function Download translation for a given content in a given language.
LingotekManagementFormBase::downloadTranslations public function Download translations for a given content in all enabled languages.
LingotekManagementFormBase::filterForm public function Form submission handler for filtering.
LingotekManagementFormBase::generateBulkOptions public function Get the bulk operations for the management form.
LingotekManagementFormBase::getAllBundles protected function Gets all the bundles as options.
LingotekManagementFormBase::getAllGroups protected function Gets all the groups as options.
LingotekManagementFormBase::getAllLanguages protected function Gets all the languages as options.
LingotekManagementFormBase::getBulkOptions protected function Gets the bulk options form array structure. 1
LingotekManagementFormBase::getDestinationWithQueryArray protected function
LingotekManagementFormBase::getRow protected function Gets a rows fo rendering based on the passed entity. 2
LingotekManagementFormBase::getSourceStatus protected function Gets the source status of an entity in a format ready to display.
LingotekManagementFormBase::getTranslationsStatuses protected function Gets the translation status of an entity in a format ready to display.
LingotekManagementFormBase::redirectToAssignJobIdMultipleEntitiesForm protected function Redirect to assign Job ID form.
LingotekManagementFormBase::redirectToClearJobIdMultipleEntitiesForm protected function Redirect to clear Job ID form.
LingotekManagementFormBase::redirectToDeleteMultipleNodesForm protected function Redirect to delete content form.
LingotekManagementFormBase::redirectToDeleteMultipleTranslationsForm protected function Redirect to delete translations form.
LingotekManagementFormBase::redirectToDeleteTranslationForm protected function Redirect to delete specific translation form.
LingotekManagementFormBase::requestTranslation public function Request translations for a given content in a given language.
LingotekManagementFormBase::requestTranslations public function Request all translations for a given content.
LingotekManagementFormBase::resetFilterForm public function Form submission handler for resetting the filters.
LingotekManagementFormBase::submitForm public function Form submission handler. Overrides FormInterface::submitForm
LingotekManagementFormBase::uploadDocument public function Upload source for translation.
LingotekManagementFormBase::__construct public function Constructs a new LingotekManagementFormBase object. 2
LingotekManagementFormHelperTrait::$tempStoreFactory protected property The tempstore factory.
LingotekManagementFormHelperTrait::getItemsPerPage protected function
LingotekManagementFormHelperTrait::setItemsPerPage protected function
LingotekSetupTrait::$lingotek protected property A lingotek connector object
LingotekSetupTrait::checkSetup protected function Verify the Lingotek Translation module has been properly initialized.
LingotekSetupTrait::setupCompleted public function Checks if Lingotek module is completely set up.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.