function ConfigSourcePluginUi::getTranslatableEntities

Gets translatable entities of a given type.

Additionally you can specify entity property conditions, pager and limit.

Parameters

string $entity_type_id: Drupal entity type.

array $property_conditions: Entity properties. There is no value processing so caller must make sure the provided entity property exists for given entity type and its value is processed.

Return value

\Drupal\Core\Config\Entity\ConfigEntityInterface[] Array of translatable entities.

1 call to ConfigSourcePluginUi::getTranslatableEntities()
ConfigSourcePluginUi::overviewForm in sources/tmgmt_config/src/ConfigSourcePluginUi.php
Builds the overview form for the source entities.

File

sources/tmgmt_config/src/ConfigSourcePluginUi.php, line 276

Class

ConfigSourcePluginUi
Config source plugin UI.

Namespace

Drupal\tmgmt_config

Code

function getTranslatableEntities($entity_type_id, $property_conditions = array()) {
  $target_status = NULL;
  $target_language = NULL;

  // We unset the target_status and target_language, because we can't filter
  // them this way.
  if (isset($property_conditions['target_status']) && isset($property_conditions['target_language'])) {
    $target_status = $property_conditions['target_status'];
    $target_language = $property_conditions['target_language'];
  }
  unset($property_conditions['target_status']);
  unset($property_conditions['target_language']);
  $search = \Drupal::entityQuery($entity_type_id);
  $search
    ->accessCheck(TRUE);

  // unset($property_conditions['target_status']);
  foreach ($property_conditions as $property_name => $property_value) {
    $search
      ->condition($property_name, $property_value, 'CONTAINS');
  }
  $result = $search
    ->execute();
  $entities = array();
  if (!empty($result)) {

    // Load the entities.
    $entities = \Drupal::entityTypeManager()
      ->getStorage($entity_type_id)
      ->loadMultiple($result);

    // @todo Optimize the code below (code duplication).
    // Remove all entities, that are already translated, because we are looking
    // for untranslated entities.
    if ($target_status == 'untranslated') {
      $entities = array_filter($entities, function (ConfigEntityInterface $entity) use ($target_language) {
        return !$this
          ->isTranslated($target_language, $entity
          ->getConfigDependencyName());
      });
    }
    elseif ($target_status == 'translated') {
      $entities = array_filter($entities, function (ConfigEntityInterface $entity) use ($target_language) {
        return $this
          ->isTranslated($target_language, $entity
          ->getConfigDependencyName());
      });
    }
  }
  return $entities;
}