You are here

function forward_views_data in Forward 8

Same name and namespace in other branches
  1. 8.3 forward.views.inc \forward_views_data()
  2. 8.2 forward.views.inc \forward_views_data()
  3. 6 forward.views.inc \forward_views_data()
  4. 7.3 views/forward.views.inc \forward_views_data()
  5. 7 forward.views.inc \forward_views_data()
  6. 7.2 views/forward.views.inc \forward_views_data()
  7. 4.x forward.views.inc \forward_views_data()
  8. 4.0.x forward.views.inc \forward_views_data()

Implements hook_views_data().

File

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

Code

function forward_views_data() {
  $data = array();

  // Forward statistics
  // Define the base group of this table. Fields that don't
  // have a group defined will go into this field by default.
  $data['forward_statistics']['table'] = array(
    'group' => t('Forward statistics'),
    'wizard_id' => 'forward_statistics',
  );

  // For other entity base tables, explain how we join.
  $entity_types = \Drupal::entityTypeManager()
    ->getDefinitions();
  foreach ($entity_types as $type => $info) {
    if (is_a($info, 'Drupal\\Core\\Entity\\ContentEntityType')) {
      if ($info
        ->getBaseTable()) {
        $data['forward_statistics']['table']['join'][$info
          ->getBaseTable() . '_field_data'] = array(
          // 'left_field' is the primary key in the referenced table.
          // 'field' is the foreign key in this table.
          'left_field' => $info
            ->getKey('id'),
          'field' => 'id',
          'extra' => array(
            array(
              'field' => 'type',
              'value' => $type,
            ),
          ),
        );
      }
    }
  }

  // Forward statistics fields.
  $data['forward_statistics']['forward_count'] = array(
    'title' => t('Forward count'),
    'help' => t('The number of times an entity was forwarded.'),
    'field' => array(
      'id' => 'numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );

  /*$data['forward_statistics']['clickthrough_count'] = array(
      'title' => t('Clickthrough count'),
      'help' => t('The number of times an entity in a forward email was clicked on.'),
      'field' => array(
        'id' => 'numeric',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'id' => 'numeric',
      ),
      'sort' => array(
        'id' => 'standard',
      ),
    );*/
  $data['forward_statistics']['last_forward_timestamp'] = array(
    'title' => t('Most recent forward'),
    'help' => t('The last time an entity was forwarded.'),
    'field' => array(
      'id' => 'date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'id' => 'date',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );

  // Forward log.
  $data['forward_log']['table'] = array(
    'group' => t('Forward log'),
    'wizard_id' => 'forward_log',
  );

  // Forward log fields.
  $data['forward_log']['path'] = array(
    'title' => t('Path'),
    'help' => t('The path that was forwarded.'),
    'field' => array(
      'id' => 'standard',
      'click sortable' => TRUE,
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'filter' => array(
      'id' => 'standard',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['forward_log']['timestamp'] = array(
    'title' => t('Timestamp'),
    'help' => t('The date and time of the forward.'),
    'field' => array(
      'id' => 'date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'id' => 'date',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['forward_log']['uid'] = array(
    'title' => t('UID'),
    'help' => t('The user ID of the user who forwarded.'),
    'field' => array(
      'id' => 'numeric',
    ),
    'argument' => array(
      'id' => 'numeric',
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'search' => array(
      'id' => 'standard',
    ),
    'relationship' => array(
      'title' => t('User'),
      'label' => t('User referenced by Forward log'),
      'help' => t('The user that forwarded.'),
      'base' => 'users',
      'base field' => 'uid',
      'id' => 'standard',
    ),
  );
  $data['forward_log']['hostname'] = array(
    'title' => t('Hostname'),
    'help' => t('Hostname of the user who forwarded.'),
    'field' => array(
      'id' => 'standard',
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'filter' => array(
      'id' => 'standard',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  return $data;
}