function opigno_module_update_8011 in Opigno module 8
Replace badge_image field with badge_media_image field.
File
- ./
opigno_module.install, line 848 - Opigno module app install/update functionality.
Code
function opigno_module_update_8011() {
// Create new field.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Badge image'))
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setSetting('target_type', 'media')
->setSetting('handler', 'default')
->setSetting('handler_settings', [
'target_bundles' => [
'image_png',
],
])
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'media_thumbnail',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_browser_entity_reference',
'weight' => 4,
'settings' => [
'entity_browser' => 'media_entity_browser_badge_images',
'field_widget_display' => 'rendered_entity',
'field_widget_remove' => TRUE,
'open' => TRUE,
'selection_mode' => 'selection_append',
'field_widget_display_settings' => [
'view_mode' => 'image_only',
],
'field_widget_edit' => FALSE,
'field_widget_replace' => FALSE,
'third_party_settings' => [
'type' => 'entity_browser_entity_reference',
],
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('badge_media_image', 'opigno_module', 'opigno_module', $field);
// Delete old field.
$old_field = FieldConfig::loadByName('opigno_module', 'opigno_module', 'badge_image');
if (!empty($old_field)) {
$old_field
->delete();
}
$old_field_storage = FieldStorageConfig::loadByName('opigno_module', 'badge_image');
if (!empty($old_field_storage)) {
$old_field_storage
->delete();
}
}