Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Created November 19, 2021 14:19
Show Gist options
  • Save levmyshkin/5f091a0cf03bc35be6e53702c729b264 to your computer and use it in GitHub Desktop.
Save levmyshkin/5f091a0cf03bc35be6e53702c729b264 to your computer and use it in GitHub Desktop.
Writing integration with Drupal Views
<?php
// from https://www.drupal.org/project/did_this_help
// https://drupalbook.org/drupal/914-writing-integration-views
/**
* @file
* Provide views data for did_this_help.module.
*/
/**
* Implements hook_views_data().
*/
function did_this_help_views_data() {
$data = [];
$data['did_this_help'] = [
'table' => [
'group' => t('Did this help?'),
'base' => [
'field' => 'id',
'title' => t('Did this help? entries'),
'help' => t('Contains a list of Did this help? entries.'),
],
],
'id' => [
'real field' => 'id',
'title' => t('Did this help? record ID'),
'help' => t('Did this help? record.'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'numeric',
],
'argument' => [
'id' => 'numeric',
],
],
];
$data['did_this_help']['path'] = [
'title' => t('Page URL for Did this help? record'),
'help' => t('Page URL for Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$data['did_this_help']['title'] = [
'title' => t('Page Title for Did this help? record'),
'help' => t('Page Title for Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$data['did_this_help']['uid'] = [
'title' => t('User ID for Did this help? record'),
'help' => t('User ID for Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'numeric',
],
'argument' => [
'id' => 'numeric',
],
'relationship' => [
'title' => t('User'),
'help' => t('The user on which the log entry as written.'),
'base' => 'users_field_data',
'base field' => 'uid',
'id' => 'standard',
],
];
$data['did_this_help']['choice'] = [
'title' => t('Yes/No choice for Did this help? record'),
'help' => t('Yes/No choice for Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'did_this_help',
],
'argument' => [
'id' => 'string',
],
];
$data['did_this_help']['choice_no'] = [
'title' => t('Answer for No choice'),
'help' => t('Answer for No choice in Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$data['did_this_help']['message'] = [
'title' => t('Message for Did this help? record'),
'help' => t('Message for Did this help? record'),
'field' => [
'id' => 'standard',
],
'sort' => [
'id' => 'standard',
],
'filter' => [
'id' => 'string',
],
'argument' => [
'id' => 'string',
],
];
$data['did_this_help']['created'] = [
'title' => t('Created date for Did this help? record'),
'help' => t('Created date for Did this help? record'),
'field' => [
'id' => 'date',
],
'argument' => [
'id' => 'date',
],
'filter' => [
'id' => 'date',
],
'sort' => [
'id' => 'date',
],
];
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment