You are here

public function AllowedLanguagesController::overview in Allowed Languages 2.x

Same name and namespace in other branches
  1. 8 src/Controller/AllowedLanguagesController.php \Drupal\allowed_languages\Controller\AllowedLanguagesController::overview()

Override overview method defined in ContentTranslationController.

Parameters

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

string $entity_type_id: (optional) The entity type ID.

Return value

array Array of page elements to render.

Overrides ContentTranslationController::overview

File

src/Controller/AllowedLanguagesController.php, line 24

Class

AllowedLanguagesController
Base class for entity translation controllers.

Namespace

Drupal\allowed_languages\Controller

Code

public function overview(RouteMatchInterface $route_match, $entity_type_id = NULL) {
  $build = parent::overview($route_match, $entity_type_id);
  $user = $this
    ->currentUser();
  if ($user
    ->hasPermission('translate all languages') || empty($build['content_translation_overview']['#rows'])) {
    return $build;
  }
  $rows =& $build['content_translation_overview']['#rows'];
  $languages = $this
    ->languageManager()
    ->getLanguages();
  $allowed_languages = \Drupal::service('allowed_languages.allowed_languages_manager')
    ->assignedLanguages();

  // Index of a row with the language in the parent output.
  $i = 0;

  // Parent overview() method does the same loop through available languages.
  foreach ($languages as $language) {

    // If the user is not allowed to manage entities in this language.
    if (!in_array($language
      ->getId(), $allowed_languages)) {
      $target_row = $rows[$i];

      // Row with operations will always be the last. See parent method.
      end($target_row);
      $operations_key = key($target_row);

      // Unset operations element in case if user can't edit entities in this language.
      unset($rows[$i][$operations_key]['data']);
    }

    // Increment the row index.
    $i++;
  }
  return $build;
}