function url_embed_update_8001 in URL Embed 8
Convert URL embed buttons to embed buttons.
@todo Can we reuse the existing UUID and save before deleting the old button?
File
- ./
url_embed.install, line 36 - Contains install and update functions for URL Embed.
Code
function url_embed_update_8001() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory
->listAll('url_embed.url_button.') as $config_name) {
$old_embed_button = $config_factory
->getEditable($config_name);
$values = $old_embed_button
->getRawData();
if (EmbedButton::load($values['id'])) {
throw new UpdateException('Unable to convert url_embed.url_button.' . $values['id'] . ' to embed.button.' . $values['id'] . ' since the latter already exists.');
}
// Move some data around.
$values['type_id'] = 'url';
$values['icon_uuid'] = $values['button_icon_uuid'];
unset($values['button_icon_uuid']);
// Save the new embed button and delete the old one.
$embed_button = EmbedButton::create($values);
$embed_button
->save();
$old_embed_button
->delete();
}
}