From f87f11b136df5195be72996b834636d09b224f29 Mon Sep 17 00:00:00 2001 From: Max Kuzmych Date: Mon, 5 Jun 2023 10:58:39 +0300 Subject: [PATCH] feat: Add min/max Grade fields for Session node --- ...tity_form_display.node.session.default.yml | 174 +++++++++--------- ...tity_view_display.node.session.default.yml | 4 + ...d.node.session.field_session_max_grade.yml | 20 ++ ...d.node.session.field_session_min_grade.yml | 20 ++ ...d.storage.node.field_session_max_grade.yml | 20 ++ ...d.storage.node.field_session_min_grade.yml | 20 ++ openy_node_session.install | 19 ++ src/SessionGrade.php | 37 ++++ 8 files changed, 232 insertions(+), 82 deletions(-) create mode 100644 config/install/field.field.node.session.field_session_max_grade.yml create mode 100644 config/install/field.field.node.session.field_session_min_grade.yml create mode 100644 config/install/field.storage.node.field_session_max_grade.yml create mode 100644 config/install/field.storage.node.field_session_min_grade.yml create mode 100644 src/SessionGrade.php diff --git a/config/install/core.entity_form_display.node.session.default.yml b/config/install/core.entity_form_display.node.session.default.yml index 4bee5c8..ee73ae3 100644 --- a/config/install/core.entity_form_display.node.session.default.yml +++ b/config/install/core.entity_form_display.node.session.default.yml @@ -13,8 +13,10 @@ dependencies: - field.field.node.session.field_session_instructor - field.field.node.session.field_session_location - field.field.node.session.field_session_max_age + - field.field.node.session.field_session_max_grade - field.field.node.session.field_session_mbr_price - field.field.node.session.field_session_min_age + - field.field.node.session.field_session_min_grade - field.field.node.session.field_session_nmbr_price - field.field.node.session.field_session_online - field.field.node.session.field_session_plocation @@ -32,82 +34,83 @@ dependencies: - link - paragraphs - path - - scheduler - text third_party_settings: field_group: group_session_info: children: - - field_session_instructor - field_session_description - field_session_gender - field_session_online - field_session_ticket - - field_availability - - field_wait_list_availability - field_session_min_age - field_session_max_age + - field_session_min_grade + - field_session_max_grade - field_session_reg_link + - field_session_instructor + - field_availability + - field_wait_list_availability - field_activity_type + label: 'Session Info' + region: content parent_name: '' weight: 4 format_type: tab format_settings: - id: '' classes: '' + id: '' formatter: closed description: '' required_fields: true - label: 'Session Info' - region: content group_membership: children: - field_session_in_mbrsh - field_session_mbr_price - field_session_nmbr_price - field_productid + label: Membership + region: content parent_name: '' weight: 5 format_type: tab format_settings: - id: '' classes: '' + id: '' formatter: closed description: '' required_fields: true - label: Membership - region: content group_location: children: - field_session_location - field_session_plocation - field_session_room + label: Location + region: content parent_name: '' weight: 3 format_type: tab format_settings: - id: '' classes: '' + id: '' formatter: closed description: '' required_fields: true - label: Location - region: content group_time: children: - field_session_time - field_session_exclusions + label: Time + region: content parent_name: '' weight: 7 format_type: tab format_settings: - id: '' classes: '' + id: '' formatter: closed description: '' required_fields: true - label: Time - region: content id: node.session.default targetEntityType: node bundle: session @@ -115,26 +118,26 @@ mode: default content: addthis: type: boolean_checkbox - settings: - display_label: true weight: 13 region: content + settings: + display_label: true third_party_settings: { } created: type: datetime_timestamp weight: 9 - settings: { } - third_party_settings: { } region: content - field_activity_type: - weight: 41 settings: { } third_party_settings: { } + field_activity_type: type: options_select + weight: 19 region: content + settings: { } + third_party_settings: { } field_availability: type: number - weight: 16 + weight: 17 region: content settings: placeholder: '' @@ -147,113 +150,125 @@ content: placeholder: '' third_party_settings: { } field_session_class: + type: entity_reference_autocomplete weight: 1 + region: content settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' - match_limit: 10 third_party_settings: { } - type: entity_reference_autocomplete - region: content field_session_description: + type: text_textarea weight: 7 + region: content settings: rows: 5 placeholder: '' third_party_settings: { } - type: text_textarea - region: content field_session_exclusions: + type: daterange_default weight: 27 + region: content settings: { } third_party_settings: { } - type: daterange_default - region: content field_session_gender: + type: options_select weight: 8 + region: content settings: { } third_party_settings: { } - type: options_select - region: content field_session_in_mbrsh: + type: boolean_checkbox weight: 10 + region: content settings: display_label: true third_party_settings: { } - type: boolean_checkbox - region: content field_session_instructor: type: string_textfield - weight: 15 + weight: 16 region: content settings: size: 60 placeholder: '' third_party_settings: { } field_session_location: + type: entity_reference_autocomplete weight: 11 + region: content settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' - match_limit: 10 third_party_settings: { } - type: entity_reference_autocomplete - region: content field_session_max_age: - weight: 13 + type: number + weight: 12 + region: content settings: placeholder: '' third_party_settings: { } - type: number + field_session_max_grade: + type: options_select + weight: 14 region: content + settings: { } + third_party_settings: { } field_session_mbr_price: + type: number weight: 11 + region: content settings: placeholder: '' third_party_settings: { } + field_session_min_age: type: number + weight: 11 region: content - field_session_min_age: - weight: 12 settings: placeholder: '' third_party_settings: { } - type: number + field_session_min_grade: + type: options_select + weight: 13 region: content + settings: { } + third_party_settings: { } field_session_nmbr_price: + type: number weight: 12 + region: content settings: placeholder: '' third_party_settings: { } - type: number - region: content field_session_online: + type: boolean_checkbox weight: 9 + region: content settings: display_label: true third_party_settings: { } - type: boolean_checkbox - region: content field_session_plocation: + type: entity_reference_autocomplete weight: 12 + region: content settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' - match_limit: 10 third_party_settings: { } - type: entity_reference_autocomplete - region: content field_session_reg_link: - weight: 14 + type: link_default + weight: 15 + region: content settings: placeholder_url: '' placeholder_title: '' third_party_settings: { } - type: link_default - region: content field_session_room: type: string_textfield weight: 16 @@ -263,15 +278,16 @@ content: placeholder: '' third_party_settings: { } field_session_ticket: + type: boolean_checkbox weight: 10 + region: content settings: display_label: true third_party_settings: { } - type: boolean_checkbox - region: content field_session_time: type: entity_reference_paragraphs weight: 26 + region: content settings: title: Paragraph title_plural: Paragraphs @@ -280,10 +296,9 @@ content: form_display_mode: default default_paragraph_type: '' third_party_settings: { } - region: content field_wait_list_availability: type: number - weight: 17 + weight: 18 region: content settings: placeholder: '' @@ -298,27 +313,21 @@ content: moderation_state: type: moderation_state_default weight: 17 - settings: { } region: content + settings: { } third_party_settings: { } path: type: path weight: 12 + region: content settings: { } third_party_settings: { } - region: content promote: type: boolean_checkbox - settings: - display_label: true weight: 10 - third_party_settings: { } region: content - publish_on: - type: datetime_timestamp_no_default - weight: 14 - region: content - settings: { } + settings: + display_label: true third_party_settings: { } redirect: type: string_textfield @@ -328,47 +337,48 @@ content: size: 60 placeholder: '' third_party_settings: { } + simple_sitemap: + weight: 10 + region: content + settings: { } + third_party_settings: { } status: type: boolean_checkbox + weight: 18 + region: content settings: display_label: true - weight: 18 third_party_settings: { } - region: content sticky: type: boolean_checkbox + weight: 11 + region: content settings: display_label: true - weight: 11 third_party_settings: { } - region: content title: type: string_textfield weight: 0 + region: content settings: size: 60 placeholder: '' third_party_settings: { } - region: content uid: type: entity_reference_autocomplete weight: 8 + region: content settings: match_operator: CONTAINS + match_limit: 10 size: 60 placeholder: '' - match_limit: 10 - third_party_settings: { } - region: content - unpublish_on: - type: datetime_timestamp_no_default - weight: 15 - region: content - settings: { } third_party_settings: { } url_redirects: weight: 50 + region: content settings: { } third_party_settings: { } - region: content -hidden: { } +hidden: + publish_on: true + unpublish_on: true diff --git a/config/install/core.entity_view_display.node.session.default.yml b/config/install/core.entity_view_display.node.session.default.yml index db87fd3..7fa481b 100644 --- a/config/install/core.entity_view_display.node.session.default.yml +++ b/config/install/core.entity_view_display.node.session.default.yml @@ -13,8 +13,10 @@ dependencies: - field.field.node.session.field_session_instructor - field.field.node.session.field_session_location - field.field.node.session.field_session_max_age + - field.field.node.session.field_session_max_grade - field.field.node.session.field_session_mbr_price - field.field.node.session.field_session_min_age + - field.field.node.session.field_session_min_grade - field.field.node.session.field_session_nmbr_price - field.field.node.session.field_session_online - field.field.node.session.field_session_plocation @@ -240,6 +242,8 @@ content: region: content hidden: field_session_instructor: true + field_session_max_grade: true + field_session_min_grade: true field_session_room: true langcode: true search_api_excerpt: true diff --git a/config/install/field.field.node.session.field_session_max_grade.yml b/config/install/field.field.node.session.field_session_max_grade.yml new file mode 100644 index 0000000..8b05b2f --- /dev/null +++ b/config/install/field.field.node.session.field_session_max_grade.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_session_max_grade + - node.type.session + module: + - options +id: node.session.field_session_max_grade +field_name: field_session_max_grade +entity_type: node +bundle: session +label: 'Max Grade' +description: 'Select List with maximum Grade option.' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: list_string diff --git a/config/install/field.field.node.session.field_session_min_grade.yml b/config/install/field.field.node.session.field_session_min_grade.yml new file mode 100644 index 0000000..27ecae8 --- /dev/null +++ b/config/install/field.field.node.session.field_session_min_grade.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_session_min_grade + - node.type.session + module: + - options +id: node.session.field_session_min_grade +field_name: field_session_min_grade +entity_type: node +bundle: session +label: 'Min Grade' +description: 'Select List with minimum Grade options.' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: list_string diff --git a/config/install/field.storage.node.field_session_max_grade.yml b/config/install/field.storage.node.field_session_max_grade.yml new file mode 100644 index 0000000..5a01395 --- /dev/null +++ b/config/install/field.storage.node.field_session_max_grade.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + module: + - node + - options +id: node.field_session_max_grade +field_name: field_session_max_grade +entity_type: node +type: list_string +settings: + allowed_values: { } + allowed_values_function: '\Drupal\openy_node_session\SessionGrade::getGrades' +module: options +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/install/field.storage.node.field_session_min_grade.yml b/config/install/field.storage.node.field_session_min_grade.yml new file mode 100644 index 0000000..bb4aa62 --- /dev/null +++ b/config/install/field.storage.node.field_session_min_grade.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + module: + - node + - options +id: node.field_session_min_grade +field_name: field_session_min_grade +entity_type: node +type: list_string +settings: + allowed_values: { } + allowed_values_function: '\Drupal\openy_node_session\SessionGrade::getGrades' +module: options +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/openy_node_session.install b/openy_node_session.install index c54bdff..22414ed 100644 --- a/openy_node_session.install +++ b/openy_node_session.install @@ -326,3 +326,22 @@ function openy_node_session_update_8014() { } } } + +/** + * Add new fields for Min/Max Grade values. + */ +function openy_node_session_update_8015() { + $config_dir = \Drupal::service('extension.list.module')->getPath('openy_node_session') . '/config/install/'; + + // Add two new fields. + $config_importer = \Drupal::service('openy_upgrade_tool.importer'); + $config_importer->setDirectory($config_dir); + $config_importer->importConfigs([ + 'field.field.node.session.field_session_max_grade', + 'field.field.node.session.field_session_min_grade', + 'field.storage.node.field_session_max_grade', + 'field.storage.node.field_session_min_grade', + 'core.entity_view_display.node.session.default', + 'core.entity_form_display.node.session.default', + ]); +} diff --git a/src/SessionGrade.php b/src/SessionGrade.php new file mode 100644 index 0000000..2509ff6 --- /dev/null +++ b/src/SessionGrade.php @@ -0,0 +1,37 @@ + new TranslatableMarkup('Pre K'), + 'K' => new TranslatableMarkup('Kindergarten'), + '1' => new TranslatableMarkup('Grade 1'), + '2' => new TranslatableMarkup('Grade 2'), + '3' => new TranslatableMarkup('Grade 3'), + '4' => new TranslatableMarkup('Grade 4'), + '5' => new TranslatableMarkup('Grade 5'), + '6' => new TranslatableMarkup('Grade 6'), + '7' => new TranslatableMarkup('Grade 7'), + '8' => new TranslatableMarkup('Grade 8'), + '9' => new TranslatableMarkup('Grade 9'), + '10' => new TranslatableMarkup('Grade 10'), + '11' => new TranslatableMarkup('Grade 11'), + '12' => new TranslatableMarkup('Grade 12'), + ]; + } + +}