You are here

function config_views_views_data in Configuration Views 8

Same name and namespace in other branches
  1. 2.0.x config_views.views.inc \config_views_views_data()

Implements hook_views_data().

File

./config_views.views.inc, line 11
Provide views data for dblog.module.

Code

function config_views_views_data() {

  /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
  $data = [];
  $typed_config = Drupal::service('config.typed');
  $all_definitions = $typed_config
    ->getDefinitions();
  $all_definitions_keys = array_keys($all_definitions);

  // Small optimization: the config entities due to their prefixed nature always
  // end up in *. Other types might have this too so these are just candidates.
  $config_keys = preg_grep('/\\*$/', $all_definitions_keys);
  $entity_types = \Drupal::entityTypeManager()
    ->getDefinitions();

  // Registers an entity area handler per entity type.

  /** @var Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_info */
  foreach ($entity_types as $entity_type => $entity_info) {
    if (!$entity_info
      ->entityClassImplements('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
      continue;
    }

    // Exclude entity types, which cannot be rendered.
    if ($entity_info
      ->hasListBuilderClass()) {
      $label = $entity_info
        ->getLabel();
      $data['views']['entity_' . $entity_type] = [
        'title' => t('Rendered entity - @label', [
          '@label' => $label,
        ]),
        'help' => t('Displays a rendered @label entity in an area.', [
          '@label' => $label,
        ]),
        'area' => [
          'entity_type' => $entity_type,
          'id' => 'entity',
        ],
      ];
    }
    if ($prefix = $entity_info
      ->getConfigPrefix()) {
      $table_name = 'config_' . str_replace('.', '_', $prefix);
      $id = $entity_info
        ->getKey('id');
      $data[$table_name]['table'] = [
        'group' => t('Config'),
        'entity type' => $entity_type,
        'entity revision' => FALSE,
      ];
      $data[$table_name]['table']['base'] = [
        'title' => $entity_info
          ->getLabel(),
        'field' => $id,
        'query_id' => 'views_config_entity_query',
      ];
      $data[$table_name][$id]['field'] = [
        'id' => 'standard',
        'title' => 'id',
      ];
      $data[$table_name]['operation'] = [
        'title' => t('Operations'),
        'help' => t('Operations'),
        'field' => [
          'id' => 'config_entity_operations',
        ],
      ];

      // We do not kno how many stars a given config prefix requires, for
      // example the schema for block is under block.block.*.*.
      $keys = preg_grep('/^' . str_replace('.', '\\.', $prefix) . '\\.\\*/', $config_keys);

      // There always will be just one. @TODO: add exception?
      $key = reset($keys);
      $definition = $all_definitions[$key];
      _views_views_config_process_schema($data[$table_name], $all_definitions, $all_definitions_keys, $definition);
    }
  }
  return $data;
}