You are here

public function LingotekConfigTranslationController::itemPage in Lingotek Translation 8

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

Language translations overview page for a configuration name.

Parameters

\Symfony\Component\HttpFoundation\Request $request: Page request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

string $plugin_id: The plugin ID of the mapper.

Return value

array Page render array.

Overrides ConfigTranslationController::itemPage

File

src/Controller/LingotekConfigTranslationController.php, line 100

Class

LingotekConfigTranslationController

Namespace

Drupal\lingotek\Controller

Code

public function itemPage(Request $request, RouteMatchInterface $route_match, $plugin_id) {
  $page = parent::itemPage($request, $route_match, $plugin_id);
  $entity = NULL;
  $entity_id = NULL;

  /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
  $mapper = $this->configMapperManager
    ->createInstance($plugin_id);
  $mapper
    ->populateFromRouteMatch($route_match);
  $languages = $this->languageManager
    ->getLanguages();
  $languages = array_filter($languages, function (LanguageInterface $language) {
    $configLanguage = ConfigurableLanguage::load($language
      ->getId());
    return $this->lingotekConfiguration
      ->isLanguageEnabled($configLanguage);
  });
  $original_langcode = $mapper
    ->getLangcode();
  if (!isset($languages[$original_langcode])) {

    // If the language is not configured on the site, create a dummy language
    // object for this listing only to ensure the user gets useful info.
    $language_name = $this->languageManager
      ->getLanguageName($original_langcode);
    $languages[$original_langcode] = new Language(array(
      'id' => $original_langcode,
      'name' => $language_name,
    ));
  }
  if ($mapper instanceof ConfigEntityMapper) {

    /** @var $mapper ConfigEntityMapper */
    $entity = $mapper
      ->getEntity();
    $entity_id = $entity
      ->id();
  }
  if ($entity_id === NULL) {
    $entity_id = $plugin_id;
  }
  foreach ($languages as $language) {
    $langcode = $language
      ->getId();
    $locale = $this->languageLocaleMapper
      ->getLocaleForLangcode($langcode);
    if ($locale && $langcode === $original_langcode) {
      $page['languages'][$langcode]['operations']['#links']['upload'] = array(
        'title' => $this
          ->t('Upload'),
        'url' => Url::fromRoute('lingotek.config.upload', [
          'entity_type' => $plugin_id,
          'entity_id' => $entity_id,
        ]),
      );
      if ($entity && ($document_id = $this->translationService
        ->getDocumentId($entity))) {
        $page['languages'][$langcode]['operations']['#links']['check_upload'] = array(
          'title' => $this
            ->t('Check upload status'),
          'url' => Url::fromRoute('lingotek.config.check_upload', [
            'entity_type' => $plugin_id,
            'entity_id' => $entity_id,
          ]),
        );
      }
      elseif ($entity_id === $plugin_id) {
        if ($document_id = $this->translationService
          ->getConfigDocumentId($mapper)) {
          $page['languages'][$langcode]['operations']['#links']['check_upload'] = array(
            'title' => $this
              ->t('Check upload status'),
            'url' => Url::fromRoute('lingotek.config.check_upload', [
              'entity_type' => $plugin_id,
              'entity_id' => $entity_id,
            ]),
          );
        }
      }
    }
    if ($locale && $langcode !== $original_langcode) {
      if (isset($page['languages'][$langcode]['operations']['#links']['add'])) {

        // If we have a config entity and it has a document id, we want to show
        // the ability of requesting translations.
        if ($entity && ($document_id = $this->translationService
          ->getDocumentId($entity))) {
          $target_status = $this->translationService
            ->getTargetStatus($entity, $langcode);
          $this
            ->generateOperationsLinks($page, $plugin_id, $entity_id, $target_status, $langcode, $locale);
        }
        elseif ($entity_id === $plugin_id && ($document_id = $this->translationService
          ->getConfigDocumentId($mapper))) {
          $target_status = $this->translationService
            ->getConfigTargetStatus($mapper, $langcode);
          $this
            ->generateOperationsLinks($page, $plugin_id, $entity_id, $target_status, $langcode, $locale);
        }
      }
      if (isset($page['languages'][$langcode]['operations']['#links']['edit'])) {
        if ($entity && ($document_id = $this->translationService
          ->getDocumentId($entity))) {
          $target_status = $this->translationService
            ->getTargetStatus($entity, $langcode);
          $this
            ->generateOperationsLinks($page, $plugin_id, $entity_id, $target_status, $langcode, $locale);
        }
        elseif ($entity_id === $plugin_id && ($document_id = $this->translationService
          ->getConfigDocumentId($mapper))) {
          $target_status = $this->translationService
            ->getConfigTargetStatus($mapper, $langcode);
          $this
            ->generateOperationsLinks($page, $plugin_id, $entity_id, $target_status, $langcode, $locale);
        }
      }
    }
  }
  return $page;
}