function smart_date_post_update_translatable_config in Smart Date 8
Same name and namespace in other branches
- 8.2 smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.x smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.0.x smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.1.x smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.2.x smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.3.x smart_date.post_update.php \smart_date_post_update_translatable_config()
- 3.4.x smart_date.post_update.php \smart_date_post_update_translatable_config()
Migrate smartdate_default field formatter settings to smartdate_custom.
File
- ./
smart_date.post_update.php, line 21 - Post-update functions for Smart Date module.
Code
function smart_date_post_update_translatable_config() {
/** @var \Drupal\Core\Entity\EntityStorageInterface $smartDateFormatStorage */
$smartDateFormatStorage = \Drupal::getContainer()
->get('entity_type.manager')
->getStorage('smart_date_format');
// Loop through all configured entity view displays, and compile information
// about the smartdate_default field settings.
$oldFormatterSettings = [];
$displays = EntityViewDisplay::loadMultiple();
foreach ($displays as $key => $display) {
if ($display instanceof EntityViewDisplay) {
$components = $display
->getComponents();
foreach ($components as $fieldName => $component) {
if (isset($component['type']) && $component['type'] === 'smartdate_default' && isset($component['settings'])) {
// Keep the settings the same but change it to the custom display.
$component['type'] = 'smartdate_custom';
$display
->setComponent($fieldName, $component);
$display
->save();
}
}
}
}
// Now ensure defaults are imported.
// If there are already smart date format entities then nothing is needed.
$storage = \Drupal::entityTypeManager()
->getStorage('smart_date_format');
$existing = $storage
->loadMultiple();
if ($existing) {
return;
}
// Obtain configuration from yaml files
$config_path = drupal_get_path('module', 'smart_date') . '/config/install/';
$source = new FileStorage($config_path);
// Load the provided default entities.
$storage
->create($source
->read('smart_date.smart_date_format.compact'))
->save();
$storage
->create($source
->read('smart_date.smart_date_format.date_only'))
->save();
$storage
->create($source
->read('smart_date.smart_date_format.default'))
->save();
$storage
->create($source
->read('smart_date.smart_date_format.time_only'))
->save();
}