function draggableviews_views_data_alter in DraggableViews 2.0.x
Same name and namespace in other branches
- 8 draggableviews.module \draggableviews_views_data_alter()
- 7.2 views/draggableviews.views.inc \draggableviews_views_data_alter()
Implements hook_views_data_alter().
File
- ./
draggableviews.module, line 19 - Contains draggableviews.module.
Code
function draggableviews_views_data_alter(&$data) {
$data['draggableviews_structure']['weight'] = [
'title' => t('DraggableViews Weight'),
'group' => t('Draggableviews'),
'help' => t('Display the weight value.'),
'field' => [
'id' => 'numeric',
],
'sort' => [
'id' => 'draggable_views_sort_default',
'help' => t('Sort by the weight value.'),
],
'filter' => [
'help' => t('Filter by the draggableviews weight value (Native handler only).'),
'id' => 'numeric',
],
'argument' => [
'id' => 'numeric',
],
];
$data['draggableviews_structure']['parent'] = [
'title' => t('Parent'),
'help' => t('The parent entity id.'),
'group' => t('Draggableviews'),
'field' => [
'id' => 'numeric',
],
'filter' => [
'help' => t("Filter by the draggableviews parent's entity id (Native handler only)."),
'id' => 'numeric',
],
'argument' => [
'id' => 'numeric',
],
];
foreach (\Drupal::entityTypeManager()
->getDefinitions() as $entity_type) {
$base_table = $entity_type
->getDataTable() ?: $entity_type
->getBaseTable();
$entity_keys = $entity_type
->getKeys();
if ($base_table && isset($data[$base_table]['table']) && isset($data[$base_table]['table']['group'])) {
$data[$base_table]['draggableviews'] = [
'title' => $data[$base_table]['table']['group'],
'group' => t('Draggableviews'),
'help' => t('Provide a draggable functionality.'),
'entity field' => $entity_keys['id'],
'field' => [
'id' => 'draggable_views_field',
'click sortable' => FALSE,
],
];
// Explain to every entity how to join with draggableviews_structure
// table.
$data['draggableviews_structure']['table']['join'][$base_table] = [
'join_id' => 'draggableviews_with_args',
// Because this is a direct link it could be left out.
'left_table' => $base_table,
'left_field' => $entity_keys['id'],
'field' => 'entity_id',
];
}
}
}