function LocaleSourcePluginUi::getStrings

Gets locale strings.

Parameters

string $textgroup: The locale textgroup.

string $search_label: Label to search for.

string $missing_target_language: Missing translation language.

string $context: The translation context.

Return value

array List of i18n strings data.

1 call to LocaleSourcePluginUi::getStrings()
LocaleSourcePluginUi::overviewForm in sources/locale/src/LocaleSourcePluginUi.php
Builds the overview form for the source entities.

File

sources/locale/src/LocaleSourcePluginUi.php, line 30

Class

LocaleSourcePluginUi
Locale source plugin UI.

Namespace

Drupal\tmgmt_locale

Code

function getStrings($search_label = NULL, $missing_target_language = NULL, $context = NULL) {
  $langcodes = array_keys(\Drupal::languageManager()
    ->getLanguages());
  $languages = array_combine($langcodes, $langcodes);
  $select = \Drupal::database()
    ->select('locales_source', 'ls')
    ->fields('ls', array(
    'lid',
    'source',
    'context',
  ));
  if (!empty($search_label)) {
    $select
      ->condition('ls.source', '%' . \Drupal::database()
      ->escapeLike($search_label) . '%', 'LIKE');
  }
  if (!empty($context)) {
    $select
      ->condition('ls.context', $context);
  }
  if (!empty($missing_target_language) && in_array($missing_target_language, $languages)) {
    $select
      ->isNull("lt_{$missing_target_language}.language");
  }

  // Join locale targets for each language.
  // We want all joined fields to be named as langcodes, but langcodes could
  // contain hyphens in their names, which is not allowed by the most database
  // engines. So we create a langcode-to-filed_alias map, and rename fields
  // later.
  $langcode_to_filed_alias_map = array();
  foreach ($languages as $langcode) {
    $table_alias = $select
      ->leftJoin('locales_target', \Drupal::database()
      ->escapeTable("lt_{$langcode}"), "ls.lid = %alias.lid AND %alias.language = '{$langcode}'");
    $langcode_to_filed_alias_map[$langcode] = $select
      ->addField($table_alias, 'language');
  }
  unset($field_alias);
  $rows = $select
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->limit(\Drupal::config('tmgmt.settings')
    ->get('source_list_limit', 20))
    ->execute()
    ->fetchAll();
  foreach ($rows as $row) {
    foreach ($langcode_to_filed_alias_map as $langcode => $field_alias) {
      $row->{$langcode} = $row->{$field_alias};
      unset($row->{$field_alias});
    }
  }
  unset($row);
  return $rows;
}