You are here

public function ScheduledTransitionFromStateViewsField::render in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/field/ScheduledTransitionFromStateViewsField.php \Drupal\scheduled_transitions\Plugin\views\field\ScheduledTransitionFromStateViewsField::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

src/Plugin/views/field/ScheduledTransitionFromStateViewsField.php, line 65

Class

ScheduledTransitionFromStateViewsField
Scheduled transition from state.

Namespace

Drupal\scheduled_transitions\Plugin\views\field

Code

public function render(ResultRow $values) {

  /** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
  $scheduledTransition = $this
    ->getEntity($values);
  $entity = $scheduledTransition
    ->getEntity();
  $workflowPlugin = $scheduledTransition
    ->getWorkflow()
    ->getTypePlugin();
  $workflowStates = $workflowPlugin ? $workflowPlugin
    ->getStates() : [];
  $entityStorage = $this->entityTypeManager
    ->getStorage($entity
    ->getEntityTypeId());
  $entityRevisionId = $scheduledTransition
    ->getEntityRevisionId();
  if (is_numeric($entityRevisionId) && $entityRevisionId > 0) {
    $entityRevision = $entityStorage
      ->loadRevision($entityRevisionId);
    $revisionTArgs = [
      '@revision_id' => $entityRevisionId,
    ];
    if ($entityRevision) {
      $fromState = $workflowStates[$entityRevision->moderation_state->value] ?? NULL;
      return $fromState ? $fromState
        ->label() : $this
        ->t('- Missing from workflow/state -');
    }
    else {
      return $this
        ->t('Deleted revision #@revision_id', $revisionTArgs);
    }
  }
  else {
    return '';
  }
}