public function DefaultDateRecurOccurrenceHandler::viewsData in Recurring Dates Field 8
Modify field views data to include occurrences.
Parameters
\Drupal\Core\Field\FieldStorageDefinitionInterface $fieldDefinition: The field definition.
array $data:
Return value
array The views data.
Overrides DateRecurOccurrenceHandlerInterface::viewsData
File
- src/
Plugin/ DateRecurOccurrenceHandler/ DefaultDateRecurOccurrenceHandler.php, line 362
Class
- DefaultDateRecurOccurrenceHandler
- Provides the default occurrence handler.
Namespace
Drupal\date_recur\Plugin\DateRecurOccurrenceHandlerCode
public function viewsData(FieldStorageDefinitionInterface $fieldDefinition, $data) {
if (empty($data)) {
return [];
}
$field_name = $fieldDefinition
->getName();
list($table_alias, $revision_table_alias) = array_keys($data);
// @todo: Revision support.
unset($data[$revision_table_alias]);
$recur_table_name = $this
->getOccurrenceCacheStorageTableName($fieldDefinition);
$field_table = $data[$table_alias];
$recur_table = $field_table;
$join_key = array_keys($field_table['table']['join'])[0];
$recur_table['table']['join'] = $field_table['table']['join'];
$recur_table['table']['join'][$join_key]['table'] = $recur_table_name;
$recur_table['table']['join'][$join_key]['extra'] = [];
// Update table name references.
$handler_keys = [
'argument',
'filter',
'sort',
'field',
];
foreach ($recur_table as $column_name => &$column_data) {
if ($column_name == 'table') {
continue;
}
if (!$this
->viewsDataCheckIfMoveColumnName($field_name, $column_name, $column_data)) {
unset($recur_table[$column_name]);
}
else {
unset($field_table[$column_name]);
foreach ($handler_keys as $key) {
if (!empty($column_data[$key]['table'])) {
$column_data[$key]['table'] = $recur_table_name;
$column_data[$key]['additional fields'] = [
$field_name . '_value',
$field_name . '_end_value',
'delta',
'field_delta',
];
}
}
if ($column_name == $field_name . '_value') {
$column_data['field']['click sortable'] = TRUE;
}
}
}
$custom_handler_name = $field_name . '_simple_render';
$recur_table[$custom_handler_name] = $recur_table[$field_name];
$recur_table[$custom_handler_name]['title'] .= $this
->t(' (simple render)');
$recur_table[$custom_handler_name]['field']['id'] = 'date_recur_field_simple_render';
$return_data = [
$recur_table_name => $recur_table,
$table_alias => $field_table,
];
return $return_data;
}