function date_recur_update_8202 in Recurring Dates Field 3.1.x
Same name and namespace in other branches
- 8.2 date_recur.install \date_recur_update_8202()
- 3.x date_recur.install \date_recur_update_8202()
- 3.0.x date_recur.install \date_recur_update_8202()
Add a default value for new 'rrule_max_length' setting on date recur fields.
Applies to attached fields only.
File
- ./
date_recur.install, line 125
Code
function date_recur_update_8202(&$sandbox) : void {
$fieldType = 'date_recur';
$entityTypeManager = \Drupal::entityTypeManager();
$entityFieldManager = \Drupal::service('entity_field.manager');
$entityFieldMap = $entityFieldManager
->getFieldMapByFieldType($fieldType);
// Iterate over all date_recur fields for all entity types.
foreach ($entityFieldMap as $entityTypeId => $fields) {
$entityStorage = $entityTypeManager
->getStorage($entityTypeId);
if (!$entityStorage instanceof SqlEntityStorageInterface) {
continue;
}
// Loads definitions for all fields (even non date_recur).
$entityFieldStorageDefinitions = $entityFieldManager
->getFieldStorageDefinitions($entityTypeId);
// Intersect date_recur fields with storage definitions for all fields.
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $fieldDefinitions */
$fieldDefinitions = array_intersect_key($entityFieldStorageDefinitions, $fields);
// Iterate over all date_recur field definitions for this entity type.
foreach ($fieldDefinitions as $fieldDefinition) {
if ($fieldDefinition instanceof FieldStorageConfig) {
// Ignore base fields, etc.
$fieldDefinition
->setSetting('rrule_max_length', 256);
$fieldDefinition
->save();
}
}
}
}