diff --git a/config/core.entity_form_display.paragraph.document_chapter.default.yml b/config/core.entity_form_display.paragraph.document_chapter.default.yml index 20dfcfbc..e62db610 100644 --- a/config/core.entity_form_display.paragraph.document_chapter.default.yml +++ b/config/core.entity_form_display.paragraph.document_chapter.default.yml @@ -5,6 +5,7 @@ dependencies: config: - entity_browser.browser.articles - field.field.paragraph.document_chapter.field_articles + - field.field.paragraph.document_chapter.field_hide_from_navigation - field.field.paragraph.document_chapter.field_short_title - field.field.paragraph.document_chapter.field_summary - field.field.paragraph.document_chapter.field_tags @@ -51,6 +52,7 @@ third_party_settings: - field_summary - field_tags - status + - field_hide_from_navigation label: 'Chapter properties' region: content parent_name: group_tabs @@ -88,11 +90,11 @@ content: weight: 2 region: content settings: + open: true entity_browser: articles field_widget_display: label field_widget_edit: '1' field_widget_remove: '1' - open: '1' selection_mode: selection_append additional_fields: options: @@ -100,6 +102,13 @@ content: field_widget_replace: 0 field_widget_display_settings: { } third_party_settings: { } + field_hide_from_navigation: + type: boolean_checkbox + weight: 8 + region: content + settings: + display_label: true + third_party_settings: { } field_short_title: type: string_textfield weight: 22 diff --git a/config/core.entity_view_display.paragraph.document_chapter.default.yml b/config/core.entity_view_display.paragraph.document_chapter.default.yml index 8bf9c7bb..97348b77 100644 --- a/config/core.entity_view_display.paragraph.document_chapter.default.yml +++ b/config/core.entity_view_display.paragraph.document_chapter.default.yml @@ -4,6 +4,7 @@ status: true dependencies: config: - field.field.paragraph.document_chapter.field_articles + - field.field.paragraph.document_chapter.field_hide_from_navigation - field.field.paragraph.document_chapter.field_short_title - field.field.paragraph.document_chapter.field_summary - field.field.paragraph.document_chapter.field_tags @@ -23,6 +24,16 @@ content: third_party_settings: { } weight: 2 region: content + field_hide_from_navigation: + type: boolean + label: above + settings: + format: default + format_custom_false: '' + format_custom_true: '' + third_party_settings: { } + weight: 3 + region: content field_summary: type: basic_string label: hidden diff --git a/config/core.entity_view_display.paragraph.document_chapter.preview.yml b/config/core.entity_view_display.paragraph.document_chapter.preview.yml index 3d01ed9a..f943842a 100644 --- a/config/core.entity_view_display.paragraph.document_chapter.preview.yml +++ b/config/core.entity_view_display.paragraph.document_chapter.preview.yml @@ -5,6 +5,7 @@ dependencies: config: - core.entity_view_mode.paragraph.preview - field.field.paragraph.document_chapter.field_articles + - field.field.paragraph.document_chapter.field_hide_from_navigation - field.field.paragraph.document_chapter.field_short_title - field.field.paragraph.document_chapter.field_summary - field.field.paragraph.document_chapter.field_tags @@ -42,6 +43,7 @@ content: weight: 0 region: content hidden: + field_hide_from_navigation: true field_short_title: true field_summary: true field_tags: true diff --git a/config/field.field.paragraph.document_chapter.field_hide_from_navigation.yml b/config/field.field.paragraph.document_chapter.field_hide_from_navigation.yml new file mode 100644 index 00000000..b2f8a455 --- /dev/null +++ b/config/field.field.paragraph.document_chapter.field_hide_from_navigation.yml @@ -0,0 +1,21 @@ +uuid: eb6f7af0-4f35-4cd0-a789-82f1e6ad8513 +langcode: en +status: true +dependencies: + config: + - field.storage.paragraph.field_hide_from_navigation + - paragraphs.paragraphs_type.document_chapter +id: paragraph.document_chapter.field_hide_from_navigation +field_name: field_hide_from_navigation +entity_type: paragraph +bundle: document_chapter +label: 'Hide in document navigation' +description: 'If checked, the chapter is marked as part of the document but should not be automatically included in the documents navigation. Useful for example for articles that are mostly shown as sub-articles in other article pages.' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + on_label: 'On' + off_label: 'Off' +field_type: boolean diff --git a/config/field.storage.paragraph.field_hide_from_navigation.yml b/config/field.storage.paragraph.field_hide_from_navigation.yml new file mode 100644 index 00000000..80674f3d --- /dev/null +++ b/config/field.storage.paragraph.field_hide_from_navigation.yml @@ -0,0 +1,18 @@ +uuid: 0472638f-b863-4754-a06c-89b9ba148312 +langcode: en +status: true +dependencies: + module: + - paragraphs +id: paragraph.field_hide_from_navigation +field_name: field_hide_from_navigation +entity_type: paragraph +type: boolean +settings: { } +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/html/modules/custom/gho_fields/gho_fields.deploy.php b/html/modules/custom/gho_fields/gho_fields.deploy.php index b2e91590..0403c990 100644 --- a/html/modules/custom/gho_fields/gho_fields.deploy.php +++ b/html/modules/custom/gho_fields/gho_fields.deploy.php @@ -23,7 +23,7 @@ function gho_fields_deploy_post_rename_datawrapper_fields(&$sandbox) { $paragraph->get('field_show_interactive_content')->setValue([ 'value' => $paragraph->get('field_show_datawrapper')->value, ]); - $paragraph->isSyncing(); + $paragraph->setSyncing(TRUE); $paragraph->save(); } } @@ -53,7 +53,7 @@ function gho_fields_deploy_migrate_bottom_figure_rows() { 'value' => $figure->second, ]); } - $paragraph->isSyncing(); + $paragraph->setSyncing(TRUE); $paragraph->save(); foreach ($paragraph->getTranslationLanguages() as $language) { @@ -74,7 +74,7 @@ function gho_fields_deploy_migrate_bottom_figure_rows() { 'value' => $figure->second, ]); } - $translated_paragraph->isSyncing(); + $translated_paragraph->setSyncing(TRUE); $translated_paragraph->save(); } } diff --git a/html/modules/custom/ncms_graphql/graphql/ncms_schema_extension.base.graphqls b/html/modules/custom/ncms_graphql/graphql/ncms_schema_extension.base.graphqls index 74514c23..87d4afa7 100644 --- a/html/modules/custom/ncms_graphql/graphql/ncms_schema_extension.base.graphqls +++ b/html/modules/custom/ncms_graphql/graphql/ncms_schema_extension.base.graphqls @@ -87,6 +87,7 @@ type DocumentChapter { title: String title_short: String summary: String + hidden: Boolean articles: [Article] } diff --git a/html/modules/custom/ncms_graphql/ncms_graphql.deploy.php b/html/modules/custom/ncms_graphql/ncms_graphql.deploy.php index 8f5c2ffc..d06ba712 100644 --- a/html/modules/custom/ncms_graphql/ncms_graphql.deploy.php +++ b/html/modules/custom/ncms_graphql/ncms_graphql.deploy.php @@ -20,7 +20,7 @@ function ncms_graphql_deploy_set_auto_visible_flag(&$sandbox) { $node->get('field_automatically_visible')->setValue([ 'value' => 1, ]); - $node->isSyncing(); + $node->setSyncing(TRUE); $node->save(); } } diff --git a/html/modules/custom/ncms_graphql/src/Plugin/GraphQL/SchemaExtension/NcmsSchemaExtension.php b/html/modules/custom/ncms_graphql/src/Plugin/GraphQL/SchemaExtension/NcmsSchemaExtension.php index 48ae8abb..a78fdaad 100644 --- a/html/modules/custom/ncms_graphql/src/Plugin/GraphQL/SchemaExtension/NcmsSchemaExtension.php +++ b/html/modules/custom/ncms_graphql/src/Plugin/GraphQL/SchemaExtension/NcmsSchemaExtension.php @@ -651,6 +651,12 @@ private function addFieldResolverDocumentChapter(ResolverRegistryInterface $regi ->map('value', $builder->fromParent()) ->map('path', $builder->fromValue('field_summary.value')), ); + $registry->addFieldResolver('DocumentChapter', 'hidden', + $builder->produce('property_path') + ->map('type', $builder->fromValue('entity:node')) + ->map('value', $builder->fromParent()) + ->map('path', $builder->fromValue('field_hide_from_navigation.value')), + ); $registry->addFieldResolver('DocumentChapter', 'articles', $builder->produce('entity_reference') ->map('entity', $builder->fromParent()) diff --git a/html/modules/custom/ncms_ui/ncms_ui.deploy.php b/html/modules/custom/ncms_ui/ncms_ui.deploy.php index 6e0f52fc..24406899 100644 --- a/html/modules/custom/ncms_ui/ncms_ui.deploy.php +++ b/html/modules/custom/ncms_ui/ncms_ui.deploy.php @@ -120,7 +120,7 @@ function ncms_ui_deploy_set_content_space_nodes(&$sandbox) { $node->get('field_content_space')->setValue([ 'target_id' => $term->id(), ]); - $node->isSyncing(); + $node->setSyncing(TRUE); $node->save(); } } @@ -199,7 +199,7 @@ function ncms_ui_deploy_set_content_space_nodes_orphaned(&$sandbox) { $node->get('field_content_space')->setValue([ 'target_id' => $term->id(), ]); - $node->isSyncing(); + $node->setSyncing(TRUE); $node->save(); } } @@ -225,7 +225,7 @@ function ncms_ui_deploy_set_content_space_media(&$sandbox) { $entity->get('field_content_space')->setValue([ 'target_id' => $term->id(), ]); - $entity->isSyncing(); + $entity->setSyncing(TRUE); $entity->save(); } } @@ -243,3 +243,54 @@ function ncms_ui_deploy_remove_obsolete_admin_menu_links() { $menu_link->delete(); } } + +/** + * Correct the changed date for content. + * + * The changed date got corrupted by + * ncms_graphql_deploy_set_auto_visible_flag(). + */ +function ncms_ui_deploy_correct_changed_date(&$sandbox) { + /** @var \Drupal\Node\NodeStorageInterface $node_storage */ + $node_storage = \Drupal::entityTypeManager()->getStorage('node'); + + /** @var \Drupal\node\NodeInterface[] $nodes */ + $nodes = $node_storage->loadByProperties([ + 'type' => ['article', 'document'], + ]); + + foreach ($nodes as $node) { + if (!$node instanceof ContentBase) { + continue; + } + + // Get all revision ids. + $revision_ids = $node_storage->revisionIds($node); + if (count($revision_ids) < 2) { + continue; + } + $revision_ids = array_values(array_reverse($revision_ids)); + + /** @var \Drupal\ncms_ui\Entity\Content\ContentBase $revision */ + $revision = $node_storage->loadRevision($revision_ids[0]); + if (!$revision) { + continue; + } + + if ($revision->getChangedTime() != 1698930576) { + continue; + } + + // Update the changed date of the current revision. + $revision->setChangedTime($revision->getRevisionCreationTime()); + $revision->setNewRevision(FALSE); + $revision->setSyncing(TRUE); + $revision->save(); + + // Update the changed date of the node. + $node->setChangedTime($revision->getRevisionCreationTime()); + $node->setNewRevision(FALSE); + $node->setSyncing(TRUE); + $node->save(); + } +} diff --git a/html/modules/custom/ncms_ui/ncms_ui.module b/html/modules/custom/ncms_ui/ncms_ui.module index dfd445fc..ac9dba05 100644 --- a/html/modules/custom/ncms_ui/ncms_ui.module +++ b/html/modules/custom/ncms_ui/ncms_ui.module @@ -13,6 +13,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Markup; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\media\MediaInterface; @@ -305,6 +306,22 @@ function ncms_ui_preprocess_layout_paragraphs_builder_component_menu(&$variables $variables['types']['layout'] = []; } +/** + * Implements hook_preprocess_hook(). + */ +function ncms_ui_preprocess_field__paragraph__field_title__document_chapter(&$variables) { + if ($variables['element']['#view_mode'] != 'preview') { + return; + } + /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */ + $paragraph = $variables['element']['#object']; + // If the chapter is marked as hidden, add a note to the title. + if ($paragraph->hasField('field_hide_from_navigation') && $paragraph->get('field_hide_from_navigation')->value) { + $variables['items'][0]['content']['#template'] .= Markup::create(' ({{ note }})'); + $variables['items'][0]['content']['#context']['note'] = t('Hidden from navigation'); + } +} + /** * Implements hook_form_FORM_ID_alter(). */ diff --git a/html/modules/custom/ncms_ui/ncms_ui.post_update.php b/html/modules/custom/ncms_ui/ncms_ui.post_update.php index 7274358b..fa284242 100644 --- a/html/modules/custom/ncms_ui/ncms_ui.post_update.php +++ b/html/modules/custom/ncms_ui/ncms_ui.post_update.php @@ -26,7 +26,7 @@ function ncms_ui_post_update_set_content_space_nodes(&$sandbox) { $node->get('field_content_space')->setValue([ 'target_id' => $term->id(), ]); - $node->isSyncing(); + $node->setSyncing(TRUE); $node->save(); } }