You are here

public function Progress::render in Translation Management Tool 8

Same name in this branch
  1. 8 src/Plugin/views/field/Progress.php \Drupal\tmgmt\Plugin\views\field\Progress::render()
  2. 8 translators/tmgmt_local/src/Plugin/views/field/Progress.php \Drupal\tmgmt_local\Plugin\views\field\Progress::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

translators/tmgmt_local/src/Plugin/views/field/Progress.php, line 20

Class

Progress
Field handler which shows the progress of a job or job item.

Namespace

Drupal\tmgmt_local\Plugin\views\field

Code

public function render(ResultRow $values) {
  $entity = $values->_entity;
  if ($entity
    ->getEntityTypeId() == 'tmgmt_local_task' && $entity
    ->getStatus() == LocalTaskInterface::STATUS_CLOSED || $entity
    ->getEntityTypeId() == 'tmgmt_local_task_item' && $entity
    ->getStatus() == LocalTaskItemInterface::STATUS_CLOSED) {
    return t('Closed');
  }
  $counts = array(
    '@untranslated' => $entity
      ->getCountUntranslated(),
    '@translated' => $entity
      ->getCountTranslated(),
    '@completed' => $entity
      ->getCountCompleted(),
  );
  $title = t('Untranslated: @untranslated, translated: @translated, completed: @completed.', $counts);
  $one_hundred_percent = array_sum($counts);
  if ($one_hundred_percent == 0) {
    return [];
  }
  $output = array(
    '#theme' => 'tmgmt_local_progress_bar',
    '#attached' => array(
      'library' => 'tmgmt/admin',
    ),
    '#title' => $title,
    '#count_untranslated' => $counts['@untranslated'],
    '#count_translated' => $counts['@translated'],
    '#count_completed' => $counts['@completed'],
    '#width_untranslated' => $counts['@untranslated'] / $one_hundred_percent * 100,
    '#width_translated' => $counts['@translated'] / $one_hundred_percent * 100,
    '#width_completed' => $counts['@completed'] / $one_hundred_percent * 100,
  );
  return $output;
}