function swagger_ui_formatter_update_8002 in Swagger UI Field Formatter 8.2
Same name and namespace in other branches
- 8.3 swagger_ui_formatter.install \swagger_ui_formatter_update_8002()
Update old field formatter IDs.
File
- ./
swagger_ui_formatter.install, line 60 - Install, update and uninstall functions for Swagger UI Field Formatter.
Code
function swagger_ui_formatter_update_8002() {
// Rebuild cache first due to updated library and class definitions and to
// avoid undefined/invalid plugin ID errors.
drupal_flush_all_caches();
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
$storage = \Drupal::entityTypeManager()
->getStorage('entity_view_display');
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
foreach ($storage
->loadMultiple() as $display) {
$display_needs_update = FALSE;
// Loop through components (enabled "non-hidden" fields and properties) and
// search for the old "swagger_ui" field formatter ID. Once one is found
// change it to the new ID and mark the display for update.
foreach ($display
->getComponents() as $name => $component) {
if (isset($component['type']) && $component['type'] === 'swagger_ui') {
$component['type'] = 'swagger_ui_file';
$display
->setComponent($name, $component);
$display_needs_update = TRUE;
}
}
if ($display_needs_update) {
$display
->save();
}
}
}