You are here

public function TaskStatus::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/TaskStatus.php, line 19

Class

TaskStatus
Field handler which shows the link for translating translation task.

Namespace

Drupal\tmgmt_local\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = parent::render($values);
  switch ($value) {
    case LocalTaskInterface::STATUS_PENDING:
      $label = t('Needs action');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg';
      break;
    case LocalTaskInterface::STATUS_COMPLETED:
      $label = t('In review');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/hourglass.svg';
      break;
    case LocalTaskInterface::STATUS_REJECTED:
      $label = t('Rejected');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/ex-red.svg';
      break;
    case LocalTaskInterface::STATUS_CLOSED:
      $label = t('Closed');
      $icon = 'core/misc/icons/73b355/check.svg';
      break;
    default:
      $label = t('Unassigned');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/rejected.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);
}