You are here

function forward_views_data_alter in Forward 8

Same name and namespace in other branches
  1. 8.3 forward.views.inc \forward_views_data_alter()
  2. 8.2 forward.views.inc \forward_views_data_alter()
  3. 4.x forward.views.inc \forward_views_data_alter()
  4. 4.0.x forward.views.inc \forward_views_data_alter()

Implements hook_views_data_alter().

File

./forward.views.inc, line 170
Provide views data for forward.module.

Code

function forward_views_data_alter(&$data) {
  $entity_types = \Drupal::entityTypeManager()
    ->getDefinitions();
  foreach ($entity_types as $type => $info) {
    if (is_a($info, 'Drupal\\Core\\Entity\\ContentEntityType')) {
      if ($info
        ->getBaseTable()) {
        $label = (string) $info
          ->getLabel();

        // Add a Forward link field
        $data[$info
          ->getBaseTable()]['forward_link'] = array(
          'field' => array(
            'title' => t('Forward link'),
            'group' => t($label),
            'help' => t('Provide a simple link to forward the @entity-type to a friend.', array(
              '@entity-type' => strtolower(t($label)),
            )),
            'id' => 'forward_link',
          ),
        );

        // Add a relationship to the logs
        $data[$info
          ->getBaseTable() . '_field_data']['forward_log'] = array(
          'title' => t('Entity with forward logs'),
          'help' => t('Relate all forward logs for the entity. Creates a row for each instance the entity was forwarded.'),
          'relationship' => array(
            'group' => t('Forward log'),
            'label' => t('Forward log referenced by entity'),
            'base' => 'forward_log',
            'base field' => 'id',
            'relationship field' => $info
              ->getKey('id'),
            'id' => 'standard',
            'extra' => array(
              array(
                'field' => 'type',
                'value' => $type,
              ),
            ),
          ),
        );
      }
    }
  }
}