You are here

public function JobState::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

src/Plugin/views/field/JobState.php, line 19

Class

JobState
Field handler which shows the state icons for jobs.

Namespace

Drupal\tmgmt\Plugin\views\field

Code

public function render(ResultRow $values) {

  /** @var \Drupal\tmgmt\JobInterface $job */
  $job = $this
    ->getEntity($values);
  switch ($job
    ->getState()) {
    case JobInterface::STATE_UNPROCESSED:
      $label = t('Unprocessed');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/rejected.svg';
      break;
    case JobInterface::STATE_ACTIVE:
      $highest_weight_icon = NULL;
      foreach ($job
        ->getItems() as $item) {
        $job_item_icon = $item
          ->getStateIcon();
        if ($job_item_icon && (!$highest_weight_icon || $highest_weight_icon['#weight'] < $job_item_icon['#weight'])) {
          $highest_weight_icon = $job_item_icon;
        }
      }
      if ($highest_weight_icon) {
        return $highest_weight_icon;
      }
      $label = t('In progress');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/hourglass.svg';
      break;
    case JobInterface::STATE_CONTINUOUS:
      $label = t('Continuous');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/continuous.svg';
      break;
    case JobInterface::STATE_CONTINUOUS_INACTIVE:
      $label = t('Continuous Inactive');
      $icon = drupal_get_path('module', 'tmgmt') . '/icons/continuous_inactive.svg';
      break;
    default:
      $icon = NULL;
      $label = NULL;
  }
  if ($icon && $label) {
    return [
      '#theme' => 'image',
      '#uri' => file_create_url($icon),
      '#title' => $label,
      '#alt' => $label,
      '#width' => 16,
      '#height' => 16,
    ];
  }
}