From 2bcd57f17df99a1b3d756c0d9265a044ddf6008b Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Mon, 18 Dec 2023 13:55:50 +0100 Subject: [PATCH] Improve --- ...r_post_update_0001_upgrade_to_thunder7.yml | 232 ------------------ thunder.post_update.php | 30 ++- 2 files changed, 18 insertions(+), 244 deletions(-) diff --git a/config/update/thunder_post_update_0001_upgrade_to_thunder7.yml b/config/update/thunder_post_update_0001_upgrade_to_thunder7.yml index a01e3f5f4..527eec933 100644 --- a/config/update/thunder_post_update_0001_upgrade_to_thunder7.yml +++ b/config/update/thunder_post_update_0001_upgrade_to_thunder7.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/thunder.post_update.php b/thunder.post_update.php index 08b54f5bc..e81b26521 100644 --- a/thunder.post_update.php +++ b/thunder.post_update.php @@ -50,18 +50,24 @@ function thunder_post_update_0001_upgrade_to_thunder7(array &$sandbox): string { /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */ $field_definition = $field_definitions[$component_name]; if ($component['type'] === 'entity_browser_entity_reference') { - $entity_form_display->setComponent($component_name, [ - 'type' => 'media_library_media_modify_widget', - 'weight' => $component['weight'], - 'settings' => [ - 'add_button_text' => 'Add media', - 'check_selected' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, - 'form_mode' => 'override', - 'no_edit_on_create' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, - 'multi_edit_on_create' => FALSE, - 'replace_checkbox_by_order_indicator' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, - ], - ]); + $target_bundles = $field_definition->getSetting('handler_settings')['target_bundles']; + $label = 'media'; + if (count($target_bundles) === 1) { + $target_type = $field_definition->getFieldStorageDefinition()->getSetting('target_type'); + $bundle_entity_type = \Drupal::entityTypeManager()->getDefinition($target_type)->getBundleEntityType(); + $bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load(reset($target_bundles)); + $label = strtolower($bundle_entity->label()); + } + $component['type'] = 'media_library_media_modify_widget'; + $component['settings'] = [ + 'add_button_text' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1 ? 'Add ' . $label . 's' : 'Add ' . $label, + 'check_selected' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, + 'form_mode' => 'override', + 'no_edit_on_create' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, + 'multi_edit_on_create' => FALSE, + 'replace_checkbox_by_order_indicator' => $field_definition->getFieldStorageDefinition()->getCardinality() !== 1, + ]; + $entity_form_display->setComponent($component_name, $component); } $entity_form_display->save(); }