public function DateRecurViewsHooks::viewsDataAlter in Recurring Dates Field 3.x
Same name and namespace in other branches
- 8.2 src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::viewsDataAlter()
- 3.0.x src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::viewsDataAlter()
- 3.1.x src/DateRecurViewsHooks.php \Drupal\date_recur\DateRecurViewsHooks::viewsDataAlter()
Implements hook_views_data_alter().
See also
\date_recur_views_data_alter()
File
- src/
DateRecurViewsHooks.php, line 191
Class
- DateRecurViewsHooks
- Defines Views hooks.
Namespace
Drupal\date_recurCode
public function viewsDataAlter(array &$data) : void {
$removeFieldKeys = $this
->getViewsPluginTypes();
$removeFieldKeys = array_flip($removeFieldKeys);
// Base fields don't yet have an option to provide defaults for their type,
// but entity views data still tries to add default views integration for
// the field primitives in
// \Drupal\views\EntityViewsData::mapSingleFieldViewsData
// Feature to add in: https://www.drupal.org/node/2489476.
// Remove the default plugins from entity views data since they are not
// something that should be supported. This also means adding plugins for
// date recur base fields cannot be added in hook_views_data or
// entity 'views_data' handlers..
// @todo bring in all plugins from \datetime_range_field_views_data() if/when
// it supports base fields.
$allFields = $this
->getDateRecurFields();
foreach ($allFields as $entityTypeId => $fields) {
/** @var \Drupal\Core\Entity\Sql\SqlEntityStorageInterface $entityStorage */
$entityStorage = $this->entityTypeManager
->getStorage($entityTypeId);
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $tableMapping */
$tableMapping = $entityStorage
->getTableMapping($fields);
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $fields */
foreach ($fields as $fieldId => $fieldStorage) {
if (!$fieldStorage instanceof BaseFieldDefinition) {
continue;
}
if ($tableMapping
->requiresDedicatedTableStorage($fieldStorage)) {
$fieldTable = $tableMapping
->getDedicatedDataTableName($fieldStorage);
$fieldData =& $data[$fieldTable];
// Remove handler keys within each field. Keys like 'title', 'help'
// etc are ignored. Whereas 'argument', 'field', etc are removed.
foreach ($fieldData as &$field) {
$field = array_diff_key($field, $removeFieldKeys);
}
}
}
}
}