You are here

function workflow_views_data_alter in Workflow 8

Implements hook_views_data_alter().

File

./workflow.views.inc, line 42
Provide Views data for workflow.module.

Code

function workflow_views_data_alter(array &$data) {

  // Provide an integration for each entity type except workflow entities.
  // Copied from comment.views.inc.
  foreach (\Drupal::entityTypeManager()
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if (WorkflowManager::isWorkflowEntityType($entity_type_id)) {
      continue;
    }
    if (!$entity_type
      ->entityClassImplements(ContentEntityInterface::class)) {
      continue;
    }
    if (!$entity_type
      ->getBaseTable()) {
      continue;
    }
    $fields = \Drupal::service('workflow.manager')
      ->getFields($entity_type_id);
    if ($fields) {
      $base_table = $entity_type
        ->getDataTable() ?: $entity_type
        ->getBaseTable();
      $args = [
        '@entity_type' => $entity_type_id,
      ];
      foreach ($fields as $field_name => $field) {
        $data[$base_table][$field_name . '_tid'] = [
          'title' => t('Workflow transitions on @entity_type using field: @field_name', $args + [
            '@field_name' => $field_name,
          ]),
          'help' => t('Relate all transitions ongit status @entity_type. This will create 1 duplicate record for every transition. Usually if you need this it is better to create a Transition view.', $args),
          'relationship' => [
            'group' => t('Workflow transition'),
            'label' => t('workflow transition'),
            'base' => 'workflow_transition_history',
            'base field' => 'entity_id',
            'relationship field' => $entity_type
              ->getKey('id'),
            'id' => 'standard',
            'extra' => [
              [
                'field' => 'entity_type',
                'value' => $entity_type_id,
              ],
              [
                'field' => 'field_name',
                'value' => $field_name,
              ],
            ],
          ],
        ];
      }
    }
  }
}