diff --git a/config/sync/core.entity_form_display.node.custom_page.default.yml b/config/sync/core.entity_form_display.node.custom_page.default.yml index 2c0b545315..5bbb92c947 100644 --- a/config/sync/core.entity_form_display.node.custom_page.default.yml +++ b/config/sync/core.entity_form_display.node.custom_page.default.yml @@ -3,7 +3,6 @@ langcode: en status: true dependencies: config: - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -83,7 +82,6 @@ content: settings: { } third_party_settings: { } hidden: - body: true created: true current_workflow_state: true og_audience: true diff --git a/config/sync/core.entity_view_display.node.custom_page.default.yml b/config/sync/core.entity_view_display.node.custom_page.default.yml index c9e48baba1..555483ff22 100644 --- a/config/sync/core.entity_view_display.node.custom_page.default.yml +++ b/config/sync/core.entity_view_display.node.custom_page.default.yml @@ -3,7 +3,6 @@ langcode: en status: true dependencies: config: - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -94,7 +93,6 @@ content: third_party_settings: { } type: link hidden: - body: true field_custom_page_logo: true langcode: true og_audience: true diff --git a/config/sync/core.entity_view_display.node.custom_page.view_mode_featured.yml b/config/sync/core.entity_view_display.node.custom_page.view_mode_featured.yml index f29100f9eb..a9927b6252 100644 --- a/config/sync/core.entity_view_display.node.custom_page.view_mode_featured.yml +++ b/config/sync/core.entity_view_display.node.custom_page.view_mode_featured.yml @@ -4,7 +4,6 @@ status: true dependencies: config: - core.entity_view_mode.node.view_mode_featured - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -35,7 +34,6 @@ content: template_suggestion: template_suggestion: '' hidden: - body: true field_attachment: true field_cp_content_listing: true field_custom_page_logo: true diff --git a/config/sync/core.entity_view_display.node.custom_page.view_mode_tile.yml b/config/sync/core.entity_view_display.node.custom_page.view_mode_tile.yml index 1aeb0e6d53..23e2efa451 100644 --- a/config/sync/core.entity_view_display.node.custom_page.view_mode_tile.yml +++ b/config/sync/core.entity_view_display.node.custom_page.view_mode_tile.yml @@ -4,7 +4,6 @@ status: true dependencies: config: - core.entity_view_mode.node.view_mode_tile - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -35,7 +34,6 @@ content: template_suggestion: template_suggestion: '' hidden: - body: true field_attachment: true field_cp_content_listing: true field_paragraphs_body: true diff --git a/config/sync/field.field.node.custom_page.body.yml b/config/sync/field.field.node.custom_page.body.yml deleted file mode 100644 index 9d0c66d224..0000000000 --- a/config/sync/field.field.node.custom_page.body.yml +++ /dev/null @@ -1,37 +0,0 @@ -uuid: 3f4c513b-f3d9-4d37-919a-375b5f8d8cb6 -langcode: en -status: true -dependencies: - config: - - field.storage.node.body - - node.type.custom_page - module: - - allowed_formats - - text -third_party_settings: - allowed_formats: - content_editor: content_editor - basic_html: '0' - eira_format: '0' - licence: '0' - restricted_html: '0' - simple_html: '0' - simple_text: '0' - full_html: '0' - plain_text: '0' -_core: - default_config_hash: MYE4qG23Xk8I6KYd15pk0PKdvWfDFQ0PNzZbw7m8UFk -id: node.custom_page.body -field_name: body -entity_type: node -bundle: custom_page -label: Body -description: '' -required: false -translatable: false -default_value: { } -default_value_callback: '' -settings: - display_summary: false - required_summary: false -field_type: text_with_summary diff --git a/web/modules/custom/custom_page/config/install/field.field.node.custom_page.body.yml b/web/modules/custom/custom_page/config/install/field.field.node.custom_page.body.yml deleted file mode 100644 index 740fdc4a25..0000000000 --- a/web/modules/custom/custom_page/config/install/field.field.node.custom_page.body.yml +++ /dev/null @@ -1,30 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - field.storage.node.body - - node.type.custom_page - module: - - allowed_formats - - text -third_party_settings: - allowed_formats: - content_editor: content_editor - basic_html: '0' - simple_html: '0' - simple_text: '0' - plain_text: '0' -id: node.custom_page.body -field_name: body -entity_type: node -bundle: custom_page -label: Body -description: '' -required: false -translatable: false -default_value: { } -default_value_callback: '' -settings: - display_summary: true - required_summary: false -field_type: text_with_summary diff --git a/web/modules/custom/custom_page/config/optional/core.entity_form_display.node.custom_page.default.yml b/web/modules/custom/custom_page/config/optional/core.entity_form_display.node.custom_page.default.yml index 90afacef2d..dc19e64ef9 100644 --- a/web/modules/custom/custom_page/config/optional/core.entity_form_display.node.custom_page.default.yml +++ b/web/modules/custom/custom_page/config/optional/core.entity_form_display.node.custom_page.default.yml @@ -2,7 +2,6 @@ langcode: en status: true dependencies: config: - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -11,29 +10,15 @@ dependencies: - image.style.thumbnail - node.type.custom_page module: - - allowed_formats - custom_page - file - image - - text + - paragraphs id: node.custom_page.default targetEntityType: node bundle: custom_page mode: default content: - body: - type: text_textarea_with_summary - weight: 2 - settings: - rows: 9 - placeholder: '' - summary_rows: 3 - show_summary: false - third_party_settings: - allowed_formats: - hide_help: '0' - hide_guidelines: '1' - region: content field_attachment: weight: 5 settings: @@ -56,6 +41,18 @@ content: third_party_settings: { } type: image_image region: content + field_paragraphs_body: + type: entity_reference_paragraphs + weight: 2 + region: content + settings: + title: Paragraph + title_plural: Paragraphs + edit_mode: open + add_mode: dropdown + form_display_mode: default + default_paragraph_type: simple_paragraph + third_party_settings: { } langcode: type: language_select weight: 1 @@ -86,7 +83,6 @@ content: hidden: created: true current_workflow_state: true - field_paragraphs_body: true og_audience: true path: true promote: true diff --git a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.default.yml b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.default.yml index a8733af131..6c02d943fa 100644 --- a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.default.yml +++ b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.default.yml @@ -2,7 +2,6 @@ langcode: en status: true dependencies: config: - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -10,6 +9,7 @@ dependencies: - field.field.node.custom_page.og_audience - node.type.custom_page module: + - entity_reference_revisions - field_group - file - link @@ -41,13 +41,6 @@ targetEntityType: node bundle: custom_page mode: default content: - body: - label: hidden - type: text_default - weight: 1 - settings: { } - third_party_settings: { } - region: content field_attachment: weight: 51 label: hidden @@ -65,6 +58,15 @@ content: label: hidden settings: { } third_party_settings: { } + field_paragraphs_body: + type: entity_reference_revisions_entity_view + weight: 1 + region: content + label: hidden + settings: + view_mode: default + link: '' + third_party_settings: { } links: weight: 0 region: content @@ -89,7 +91,6 @@ content: type: link hidden: field_custom_page_logo: true - field_paragraphs_body: true langcode: true og_audience: true published_at: true diff --git a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_featured.yml b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_featured.yml index eb8874e84e..0736f0a58e 100644 --- a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_featured.yml +++ b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_featured.yml @@ -3,7 +3,6 @@ status: true dependencies: config: - core.entity_view_mode.node.view_mode_featured - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -11,6 +10,7 @@ dependencies: - field.field.node.custom_page.og_audience - node.type.custom_page module: + - entity_reference_revisions - smart_trim - template_suggestion - user @@ -19,31 +19,21 @@ targetEntityType: node bundle: custom_page mode: view_mode_featured content: - body: - label: hidden - type: smart_trim + field_paragraphs_body: + type: entity_reference_revisions_entity_view weight: 0 + region: content + label: hidden settings: - trim_length: 200 - trim_type: chars - trim_suffix: … - more_link: false - more_text: More - summary_handler: trim - trim_options: - text: false - more_class: more-link - wrap_output: false - wrap_class: trimmed + view_mode: preview + link: '' third_party_settings: template_suggestion: template_suggestion: '' - region: content hidden: field_attachment: true field_cp_content_listing: true field_custom_page_logo: true - field_paragraphs_body: true langcode: true links: true node_field_cp_content_listing_top: true diff --git a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_tile.yml b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_tile.yml index ac4a7c00ed..a48c2c7b2a 100644 --- a/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_tile.yml +++ b/web/modules/custom/custom_page/config/optional/core.entity_view_display.node.custom_page.view_mode_tile.yml @@ -3,7 +3,6 @@ status: true dependencies: config: - core.entity_view_mode.node.view_mode_tile - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo @@ -32,7 +31,6 @@ content: template_suggestion: template_suggestion: '' hidden: - body: true field_attachment: true field_cp_content_listing: true field_paragraphs_body: true diff --git a/web/modules/custom/custom_page/custom_page.info.yml b/web/modules/custom/custom_page/custom_page.info.yml index b9b331a823..89664ed96b 100644 --- a/web/modules/custom/custom_page/custom_page.info.yml +++ b/web/modules/custom/custom_page/custom_page.info.yml @@ -23,7 +23,6 @@ config_devel: - core.base_field_override.node.custom_page.title - facets.facet.field_cp_content_listing_content_type - facets.facet_source.search_api_field__node.field_cp_content_listing - - field.field.node.custom_page.body - field.field.node.custom_page.field_attachment - field.field.node.custom_page.field_cp_content_listing - field.field.node.custom_page.field_custom_page_logo diff --git a/web/modules/custom/custom_page/custom_page.post_update.php b/web/modules/custom/custom_page/custom_page.post_update.php deleted file mode 100644 index 2098d63bef..0000000000 --- a/web/modules/custom/custom_page/custom_page.post_update.php +++ /dev/null @@ -1,38 +0,0 @@ -query("SELECT nid FROM {node_field_data} n WHERE n.type = 'custom_page';")->fetchCol(); - $sandbox['count'] = 0; - $sandbox['max'] = count($sandbox['nids']); - } - - $limit = 10; - $nids = array_splice($sandbox['nids'], 0, $limit); - $node_storage = \Drupal::entityTypeManager()->getStorage('node'); - foreach ($node_storage->loadMultiple($nids) as $custom_page) { - $paragraph = Paragraph::create([ - 'type' => 'simple_paragraph', - ]); - $paragraph->set('field_body', $custom_page->get('body')->getValue()); - $paragraph->save(); - $custom_page->set('field_paragraphs_body', $paragraph); - $custom_page->save(); - $sandbox['count']++; - } - - $sandbox['#finished'] = (int) empty($sandbox['nids']); - return "Processed {$sandbox['count']} items out of {$sandbox['max']}."; -} diff --git a/web/modules/custom/joinup_core/joinup_core.post_update.php b/web/modules/custom/joinup_core/joinup_core.post_update.php index 49751978fd..51f0ad6d8e 100644 --- a/web/modules/custom/joinup_core/joinup_core.post_update.php +++ b/web/modules/custom/joinup_core/joinup_core.post_update.php @@ -6,3 +6,109 @@ */ declare(strict_types = 1); + +/** + * Migrate the body field to the new paragraphs field for custom pages. + */ +function joinup_core_post_update_0106101(array &$sandbox): string { + $db = \Drupal::database(); + /** @var \Drupal\Component\Uuid\UuidInterface $uuid */ + $uuid = \Drupal::service('uuid'); + + if (!isset($sandbox['nids'])) { + $sandbox['nids'] = $db->query("SELECT nid FROM {node_field_data} n WHERE n.type = 'custom_page'")->fetchCol(); + $sandbox['max'] = count($sandbox['nids']); + // The paragraph ID. + $sandbox['id'] = 0; + // The paragraph revision ID. + $sandbox['revision_id'] = 0; + } + + $nids_to_process = array_splice($sandbox['nids'], 0, 150); + foreach ($nids_to_process as $nid) { + $sandbox['id']++; + + // Get all revision data for a given custom page. + $revisions = $db->query("SELECT nfr.nid, nfr.vid, nr.revision_timestamp AS created, nrb.body_value AS body FROM {node_field_revision} nfr INNER JOIN {node_field_data} nfd ON nfr.nid = nfd.nid INNER JOIN {node_revision} nr ON nfr.vid = nr.vid LEFT JOIN {node_revision__body} nrb ON nfr.vid = nrb.revision_id WHERE nfd.type = 'custom_page' AND nfr.nid = :nid ORDER BY nfr.vid", [ + ':nid' => $nid, + ])->fetchAll(); + + // First update the revision tables. As we're sorted by the node revision + // ID, the last iteration value is also used later as default values. + foreach ($revisions as $revision) { + $sandbox['revision_id']++; + if (!empty($revision->body)) { + $body_row = [ + 'bundle' => 'simple_paragraph', + 'entity_id' => $sandbox['id'], + 'revision_id' => $sandbox['revision_id'], + 'langcode' => 'en', + 'delta' => 0, + 'field_body_value' => $revision->body, + 'field_body_format' => 'content_editor', + ]; + $db->insert('paragraph_revision__field_body')->fields($body_row)->execute(); + } + $data_row = [ + 'id' => $sandbox['id'], + 'revision_id' => $sandbox['revision_id'], + 'langcode' => 'en', + 'status' => 1, + 'created' => $revision->created, + 'parent_id' => $nid, + 'parent_type' => 'node', + 'parent_field_name' => 'field_paragraphs_body', + 'behavior_settings' => 'a:0:{}', + 'default_langcode' => 1, + 'revision_translation_affected' => 1, + ]; + $db->insert('paragraphs_item_revision_field_data')->fields($data_row)->execute(); + $db->insert('paragraphs_item_revision')->fields([ + 'id' => $sandbox['id'], + 'revision_id' => $sandbox['revision_id'], + 'langcode' => 'en', + 'revision_default' => 1, + ])->execute(); + + // Add a record in the node revision 'field_paragraphs_body' field. + $host_entity_data = [ + 'bundle' => 'custom_page', + 'deleted' => 0, + 'entity_id' => $nid, + 'revision_id' => $revision->vid, + 'langcode' => 'en', + 'delta' => 0, + 'field_paragraphs_body_target_id' => $sandbox['id'], + 'field_paragraphs_body_target_revision_id' => $sandbox['revision_id'], + ]; + $db->insert('node_revision__field_paragraphs_body')->fields($host_entity_data)->execute(); + } + + // Update main tables. + if (!empty($revision->body)) { + $db->insert('paragraph__field_body')->fields($body_row)->execute(); + } + $data_row['type'] = 'simple_paragraph'; + $db->insert('paragraphs_item_field_data')->fields($data_row)->execute(); + $db->insert('paragraphs_item')->fields([ + 'id' => $sandbox['id'], + 'revision_id' => $sandbox['revision_id'], + 'type' => 'simple_paragraph', + 'uuid' => $uuid->generate(), + 'langcode' => 'en', + ])->execute(); + + // Add a record in the node 'field_paragraphs_body' field. + $db->insert('node__field_paragraphs_body')->fields($host_entity_data)->execute(); + } + + $sandbox['#finished'] = (int) empty($sandbox['nids']); + + if ($sandbox['#finished']) { + // Cleanup stale body content. + $db->delete('node__body')->condition('bundle', 'custom_page')->execute(); + $db->delete('node_revision__body')->condition('bundle', 'custom_page')->execute(); + } + + return "Processed {$sandbox['id']} items out of {$sandbox['max']}."; +}