addtocal.install in Add to Cal 8.2
File
addtocal.install
View source
<?php
function addtocal_update_8200(&$sandbox) {
$entity_view_display_storage = \Drupal::entityTypeManager()
->getStorage('entity_view_display');
$entity_view_displays = $entity_view_display_storage
->loadMultiple();
foreach ($entity_view_displays as $entity_view_display) {
foreach ($entity_view_display
->getComponents() as $name => $component) {
$type = $component['type'] ?? '';
if ($type == 'addtocal_view') {
$location = $component['settings']['location'] ?? '';
if (!is_string($location)) {
if (!empty($location['tokenized'])) {
$location = $location['tokenized'];
}
elseif (!empty($location['value'])) {
$location = '[' . $entity_view_display
->getTargetEntityTypeId() . ':' . $location['value'] . ']';
}
else {
$location = '';
}
$component['settings']['location'] = $location;
}
$description = $component['settings']['description'] ?? '';
if (!is_string($description)) {
if (!empty($description['tokenized'])) {
$description = $description['tokenized'];
}
elseif (!empty($description['value'])) {
$description = '[' . $entity_view_display
->getTargetEntityTypeId() . ':' . $description['value'] . ']';
}
else {
$description = '';
}
$component['settings']['description'] = $description;
}
$entity_view_display
->setComponent($name, $component);
$entity_view_display
->save();
}
}
}
}