You are here

public function WorkflowTransitionListBuilder::buildRow in Workflow 8

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/WorkflowTransitionListBuilder.php, line 91

Class

WorkflowTransitionListBuilder
Defines a class to build a draggable listing of Workflow State entities.

Namespace

Drupal\workflow

Code

public function buildRow(EntityInterface $transition) {

  // Show the history table.

  /** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $transition */
  $current_themed = FALSE;
  $entity = $transition
    ->getTargetEntity();
  $field_name = $transition
    ->getFieldName();
  $current_sid = workflow_node_current_state($entity, $field_name);
  $to_state = $transition
    ->getToState();
  if (!$to_state) {

    // This is an invalid/deleted state.
    $to_label = self::WORKFLOW_MARK_STATE_IS_DELETED;

    // Add a footer to explain the addition.
    $this->footer_needed = TRUE;
  }
  else {
    $label = Html::escape($this
      ->t($to_state
      ->label()));
    if ($transition
      ->getToSid() == $current_sid && $to_state
      ->isActive() && !$current_themed) {
      $to_label = $label;

      // Make a note that we have themed the current state; other times in the history
      // of this entity where the entity was in this state do not need to be specially themed.
      $current_themed = TRUE;
    }
    elseif (!$to_state
      ->isActive()) {
      $to_label = $label . self::WORKFLOW_MARK_STATE_IS_DELETED;

      // Add a footer to explain the addition.
      $this->footer_needed = TRUE;
    }
    else {

      // Regular state.
      $to_label = $label;
    }
  }
  unset($to_state);
  $from_state = $transition
    ->getFromState();
  if (!$from_state) {

    // This is an invalid/deleted state.
    $from_label = self::WORKFLOW_MARK_STATE_IS_DELETED;

    // Add a footer to explain the addition.
    $this->footer_needed = TRUE;
  }
  else {
    $label = Html::escape($this
      ->t($from_state
      ->label()));
    if (!$from_state
      ->isActive()) {
      $from_label = $label . self::WORKFLOW_MARK_STATE_IS_DELETED;

      // Add a footer to explain the addition.
      $this->footer_needed = TRUE;
    }
    else {

      // Regular state.
      $from_label = $label;
    }
  }
  unset($from_state);
  $owner = $transition
    ->getOwner();
  $field_label = $transition
    ->getFieldName();
  $variables = [
    'transition' => $transition,
    'extra' => '',
    'from_label' => $from_label,
    'to_label' => $to_label,
    'user' => $owner,
  ];

  // Allow other modules to modify the row.
  \Drupal::moduleHandler()
    ->alter('workflow_history', $variables);

  // 'class' => array('workflow_history_row'), // @todo D8-port.
  $row['timestamp']['data'] = $transition
    ->getTimestampFormatted();

  // 'class' => array('timestamp')
  // html_entity_decode() transforms chars like '&' correctly.
  if ($this
    ->showColumnFieldname($entity)) {
    $row['field_name']['data'] = html_entity_decode($field_label);
  }
  $row['from_state']['data'] = html_entity_decode($from_label);

  // 'class' => array('previous-state-name'))
  $row['to_state']['data'] = html_entity_decode($to_label);

  // 'class' => array('state-name'))
  $row['user_name']['data'] = $owner
    ->toLink($owner
    ->getDisplayName())
    ->toString();

  // 'class' => array('user-name')
  $row['comment']['data'] = html_entity_decode($transition
    ->getComment());

  // 'class' => array('log-comment')
  $row += parent::buildRow($transition);
  return $row;
}