Skip to content

Commit

Permalink
Dynamic Entity Browser migration
Browse files Browse the repository at this point in the history
* Dynamic entity browser field widget migration

* Improve

* Switch to select

* Fix

* Simplify

* Fix

---------

Co-authored-by: Christian Fritsch <[email protected]>
  • Loading branch information
chrfritsch and Christian Fritsch authored Dec 19, 2023
1 parent 6447fc8 commit c30600b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 233 deletions.
232 changes: 0 additions & 232 deletions config/update/thunder_post_update_0001_upgrade_to_thunder7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,92 +301,16 @@ system.theme:
admin: gin
core.entity_form_display.media.gallery.default:
expected_config:
content:
field_media_images:
settings:
entity_browser: multiple_image_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_edit
type: entity_browser_entity_reference
third_party_settings:
field_group:
group_basis:
label: Basis
update_actions:
delete:
content:
field_media_images:
settings:
entity_browser: multiple_image_browser
field_widget_display: rendered_entity
field_widget_display_settings: true
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_edit
change:
content:
field_media_images:
settings:
add_button_text: 'Select images'
check_selected: true
form_mode: override
media_types: { }
no_edit_on_create: true
multi_edit_on_create: false
replace_checkbox_by_order_indicator: true
type: media_library_media_modify_widget
third_party_settings:
field_group:
group_basis:
label: ''
core.entity_form_display.media.gallery.inline:
expected_config:
content:
field_media_images:
settings:
entity_browser: multiple_image_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_edit
type: entity_browser_entity_reference
update_actions:
delete:
content:
field_media_images:
settings:
entity_browser: multiple_image_browser
field_widget_display: rendered_entity
field_widget_display_settings: true
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_edit
change:
content:
field_media_images:
settings:
add_button_text: 'Select images'
check_selected: true
form_mode: override
media_types: { }
no_edit_on_create: true
multi_edit_on_create: false
replace_checkbox_by_order_indicator: true
type: media_library_media_modify_widget
core.entity_form_display.media.image.default:
expected_config:
third_party_settings:
Expand Down Expand Up @@ -481,20 +405,6 @@ core.entity_form_display.node.article.bulk_edit:
weight: 10
core.entity_form_display.node.article.default:
expected_config:
content:
field_teaser_media:
settings:
entity_browser: image_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
third_party_settings: { }
type: entity_browser_entity_reference
third_party_settings:
field_group:
group_basis:
Expand All @@ -506,18 +416,6 @@ core.entity_form_display.node.article.default:
group_teaser:
label: Teaser
update_actions:
delete:
content:
field_teaser_media:
settings:
entity_browser: image_browser
field_widget_display: rendered_entity
field_widget_display_settings: true
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
add:
third_party_settings:
field_group:
Expand All @@ -531,29 +429,6 @@ core.entity_form_display.node.article.default:
format_settings:
show_empty_fields: false
change:
content:
field_teaser_media:
settings:
add_button_text: 'Select image'
check_selected: false
form_mode: override
media_types: { }
no_edit_on_create: false
multi_edit_on_create: false
replace_checkbox_by_order_indicator: false
third_party_settings:
entity_reference_actions:
enabled: false
options:
action_title: Action
include_exclude: exclude
selected_actions:
media_delete_action: '0'
media_edit_action: '0'
media_publish_action: '0'
media_save_action: '0'
media_unpublish_action: '0'
type: media_library_media_modify_widget
third_party_settings:
field_group:
group_basis:
Expand Down Expand Up @@ -593,113 +468,6 @@ core.entity_form_display.node.page.default:
group_paragraphs:
label: ''
weight: 1
core.entity_form_display.paragraph.image.default:
expected_config:
content:
field_image:
settings:
entity_browser: image_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
third_party_settings: { }
type: entity_browser_entity_reference
update_actions:
delete:
content:
field_image:
settings:
entity_browser: image_browser
field_widget_display: rendered_entity
field_widget_display_settings: true
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
change:
content:
field_image:
settings:
add_button_text: 'Select image'
check_selected: false
form_mode: override
media_types: { }
no_edit_on_create: false
multi_edit_on_create: false
replace_checkbox_by_order_indicator: false
third_party_settings:
entity_reference_actions:
enabled: false
options:
action_title: Action
include_exclude: exclude
selected_actions:
media_delete_action: '0'
media_edit_action: '0'
media_publish_action: '0'
media_save_action: '0'
media_unpublish_action: '0'
type: media_library_media_modify_widget
core.entity_form_display.paragraph.video.default:
expected_config:
content:
field_video:
settings:
entity_browser: video_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
third_party_settings: { }
type: entity_browser_entity_reference
update_actions:
delete:
content:
field_video:
settings:
entity_browser: video_browser
field_widget_display: rendered_entity
field_widget_display_settings:
view_mode: thumbnail
field_widget_edit: true
field_widget_remove: true
field_widget_replace: false
open: true
selection_mode: selection_append
change:
content:
field_video:
settings:
add_button_text: 'Select video'
check_selected: false
form_mode: override
media_types: { }
no_edit_on_create: false
multi_edit_on_create: false
replace_checkbox_by_order_indicator: false
third_party_settings:
entity_reference_actions:
enabled: false
options:
action_title: Action
include_exclude: exclude
selected_actions:
media_delete_action: '0'
media_edit_action: '0'
media_publish_action: '0'
media_save_action: '0'
media_unpublish_action: '0'
type: media_library_media_modify_widget
core.entity_view_display.media.gallery.paragraph_preview:
expected_config:
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function resolveFields(): void {
if (!empty($values['url'])) {
return $values + ['src' => $values['url']];
}
return;
return $values;
})
)
);
Expand Down
29 changes: 29 additions & 0 deletions thunder.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Update functions for the thunder installation profile.
*/

use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\user\Entity\Role;

Expand Down Expand Up @@ -40,6 +41,34 @@ function thunder_post_update_0001_upgrade_to_thunder7(array &$sandbox): string {
$role->save();
}

foreach (EntityFormDisplay::loadMultiple() as $entity_form_display) {
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_form_display->getTargetEntityTypeId(), $entity_form_display->getTargetBundle());
foreach ($entity_form_display->getComponents() as $component_name => $component) {
if (!isset($field_definitions[$component_name])) {
continue;
}
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$field_definition = $field_definitions[$component_name];
if ($component['type'] === 'entity_browser_entity_reference' && $field_definition->getFieldStorageDefinition()->getSetting('target_type') === 'media') {
$multiple = $field_definition->getFieldStorageDefinition()->getCardinality() !== 1;
$component['type'] = 'media_library_media_modify_widget';
$component['settings'] = [
'add_button_text' => Drupal::translation()->formatPlural($multiple ? 2 : 1, 'Select @label', 'Select @labels', [
'@label' => 'media item',
'@labels' => 'media items',
]),
'check_selected' => $multiple,
'form_mode' => 'override',
'no_edit_on_create' => $multiple,
'multi_edit_on_create' => FALSE,
'replace_checkbox_by_order_indicator' => $multiple,
];
$entity_form_display->setComponent($component_name, $component);
}
$entity_form_display->save();
}
}

/** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
$moduleInstaller = \Drupal::service('module_installer');
$moduleInstaller->uninstall([
Expand Down

0 comments on commit c30600b

Please sign in to comment.