You are here

public function TaskItemStatus::render in Translation Management Tool 8

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 NumericField::render

File

translators/tmgmt_local/src/Plugin/views/field/TaskItemStatus.php, line 19

Class

TaskItemStatus
Field handler which shows the link for translating translation task items.

Namespace

Drupal\tmgmt_local\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = parent::render($values);
  switch ($value) {
    case LocalTaskItemInterface::STATUS_PENDING:
      $label = t('Untranslated');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg';
      break;
    case LocalTaskItemInterface::STATUS_COMPLETED:
      $label = t('Translated');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/gray-check.svg';
      break;
    case LocalTaskItemInterface::STATUS_REJECTED:
      $label = t('Rejected');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/rejected.svg';
      break;
    case LocalTaskItemInterface::STATUS_CLOSED:
      $label = t('Completed');
      $icon = 'core/misc/icons/73b355/check.svg';
      break;
    default:
      $label = t('Untranslated');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg';
  }
  $element = [
    '#type' => 'inline_template',
    '#template' => '<img src="{{ icon }}" title="{{ label }}"><span></span></img>',
    '#context' => array(
      'icon' => file_create_url($icon),
      'label' => $label,
    ),
  ];
  return \Drupal::service('renderer')
    ->render($element);
}