/**
  * {@inheritdoc}
  *
  * Building the header and content lines for the contact list.
  *
  * Calling the parent::buildHeader() adds a column for the possible actions
  * and inserts the 'edit' and 'delete' links as defined for the entity type.
  */
 public function buildHeader()
 {
     $entity = $this->workflow_entity;
     // N.B. This is a custom variable.
     $field_name = workflow_url_get_field_name();
     $header['timestamp'] = $this->t('Date');
     if ($this->showColumnFieldname($entity)) {
         $header['field_name'] = $this->t('Field name');
     }
     $header['from_state'] = $this->t('From State');
     $header['to_state'] = $this->t('To State');
     $header['user_name'] = $this->t('By');
     $header['comment'] = $this->t('Comment');
     // column 'Operations' is now added by core.
     //$header['operations'] = $this->t('Operations');
     return $header + parent::buildHeader();
 }
 /**
  * Menu access control callback. Checks access to Workflow tab.
  *
  * This used to be D7-function workflow_tab_access($user, $entity).
  *
  * The History tab should not be used with multiple workflows per entity.
  * Use the dedicated view for this use case.
  * @todo D8: remove this in favour of View 'Workflow history per entity'.
  * @todo D8-port: make this workf for non-Node entity types.
  *
  * @param \Drupal\workflow\Controller\AccountInterface $account
  *   Run access checks for this account.
  *
  * @return \Drupal\Core\Access\AccessResult
  */
 public function historyAccess(AccountInterface $account)
 {
     static $access = array();
     $uid = $account ? $account->id() : -1;
     // TODO D8-port: make Workflow History tab happen for every entity_type.
     // @see workflow.routing.yml, workflow.links.task.yml, WorkflowTransitionListController.
     // ATM it only works for Nodes and Terms.
     // This is a hack. The Route should always pass an object.
     // On view tab, $entity is object,
     // On workflow tab, $entity is id().
     // Get the entity for this form.
     $entity = workflow_url_get_entity();
     /* @var $entity EntityInterface */
     // Figure out the $entity's bundle and id.
     $entity_type = $entity->getEntityTypeId();
     $entity_bundle = $entity->bundle();
     $entity_id = $entity ? $entity->id() : '';
     $field_name = workflow_url_get_field_name();
     if (isset($access[$uid][$entity_type][$entity_id][$field_name ? $field_name : 'no_field'])) {
         return $access[$uid][$entity_type][$entity_id][$field_name ? $field_name : 'no_field'];
     }
     $access_result = AccessResult::forbidden();
     // When having multiple workflows per bundle, use Views display
     // 'Workflow history per entity' instead!
     $fields = _workflow_info_fields($entity, $entity_type, $entity_bundle, $field_name);
     if (!$fields) {
         return AccessResult::forbidden();
     } else {
         // @todo: Keep below code aligned between WorkflowState, ~Transition, ~TransitionListController
         $uid = $account ? $account->id() : -1;
         $entity_id = $entity ? $entity->id() : '';
         // Determine if user is owner of the entity.
         $is_owner = WorkflowManager::isOwner($account, $entity);
         /**
          * Determine if user has Access. Fill the cache.
          */
         // @todo: what to do with multiple workflow_fields per bundle? Use Views instead! Or introduce a setting.
         // @TODO D8-port: workflow_tab_access: use proper 'WORKFLOW_TYPE' permissions
         foreach ($fields as $definition) {
             $type_id = $definition->getSetting('workflow_type');
             if ($account->hasPermission("access any {$type_id} workflow_transion overview")) {
                 $access_result = AccessResult::allowed();
             } elseif ($is_owner && $account->hasPermission("access own {$type_id} workflow_transion overview")) {
                 $access_result = AccessResult::allowed();
             } elseif ($account->hasPermission('administer nodes')) {
                 $access_result = AccessResult::allowed();
             }
             $access[$uid][$entity_type][$entity_id][$field_name ? $field_name : 'no_field'] = $access_result;
         }
     }
     return $access_result;
 }