function date_recur_update_8206 in Recurring Dates Field 3.x
Same name and namespace in other branches
- 8.2 date_recur.install \date_recur_update_8206()
- 3.0.x date_recur.install \date_recur_update_8206()
- 3.1.x date_recur.install \date_recur_update_8206()
Removes default time zone setting from widgets extending basic widget.
File
- ./
date_recur.install, line 293
Code
function date_recur_update_8206(&$sandbox) : void {
// Get widgets implementing the same class as basic widget.
/** @var \Drupal\Core\Field\WidgetPluginManager $fieldWidgetPluginManager */
$basicWidgetClass = DateRecurBasicWidget::class;
$basicWidgetDerivativeWidgetIds = [];
$basicWidgetDerivativeWidgetIds[] = 'date_recur_basic_widget';
$fieldWidgetPluginManager = \Drupal::service('plugin.manager.field.widget');
foreach ($fieldWidgetPluginManager
->getDefinitions() as $widgetId => $definition) {
$class = $definition['class'];
if (class_exists($class) && (new \ReflectionClass($class))
->isSubclassOf($basicWidgetClass)) {
$basicWidgetDerivativeWidgetIds[] = $widgetId;
}
}
// Find form displays using any of the widgets extending basic widget.
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface[] $displays */
$displays = EntityFormDisplay::loadMultiple();
foreach ($displays as $display) {
$updated = 0;
$components = $display
->getComponents();
foreach ($components as $component => $options) {
$widgetId = $options['type'] ?? NULL;
if (in_array($widgetId, $basicWidgetDerivativeWidgetIds)) {
// Unset the old setting.
unset($options['settings']['timezone_override']);
$updated++;
$display
->setComponent($component, $options);
}
}
if ($updated > 0) {
$display
->save();
}
}
}