You are here

public function LingotekTargetStatus::preRender in Lingotek Translation 3.3.x

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

Calculates the url and status title and adds them to the render array.

Parameters

array $element: The element as a render array.

Return value

array The element as a render array.

File

src/Element/LingotekTargetStatus.php, line 47

Class

LingotekTargetStatus
Provides a Lingotek target status element.

Namespace

Drupal\lingotek\Element

Code

public function preRender(array $element) {
  $isSourceLanguage = $element['#entity']
    ->language()
    ->getId() === $element['#language'];
  if ($isSourceLanguage) {
    return [];
  }
  if (NULL === ConfigurableLanguage::load($element['#language'])) {
    return [];
  }
  $element['#url'] = $this
    ->getTargetActionUrl($element['#entity'], $element['#status'], $element['#language']);
  $element['#new_window'] = !($element['#entity']
    ->hasTranslation($element['#language']) && $element['#status'] == Lingotek::STATUS_REQUEST) && in_array($element['#status'], [
    Lingotek::STATUS_CURRENT,
    Lingotek::STATUS_INTERMEDIATE,
    Lingotek::STATUS_EDITED,
  ]);
  $element['#status_text'] = $this
    ->getTargetStatusText($element['#entity'], $element['#status'], $element['#language']);
  return $element;
}