diff --git a/config/sync/core.entity_form_display.node.service_region.default.yml b/config/sync/core.entity_form_display.node.service_region.default.yml index e8304cad85..dac66a5dd7 100644 --- a/config/sync/core.entity_form_display.node.service_region.default.yml +++ b/config/sync/core.entity_form_display.node.service_region.default.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.service_region.field_service_location - field.field.node.service_region.field_service_name_and_descripti - field.field.node.service_region.field_vba_region_facility_list + - field.field.node.service_region.field_vba_serv_reg_appt_default - node.type.service_region - workflows.workflow.restricted_archive module: @@ -39,7 +40,6 @@ third_party_settings: description_display: after group_primary_facility: children: - - field_office - field_facility_location - field_service_location label: 'Primary facility' @@ -169,6 +169,7 @@ hidden: body: true created: true field_last_saved_by_an_editor: true + field_vba_serv_reg_appt_default: true langcode: true path: true promote: true diff --git a/config/sync/core.entity_form_display.node.vba_facility_service.default.yml b/config/sync/core.entity_form_display.node.vba_facility_service.default.yml index cd7c258364..e2b45e3535 100644 --- a/config/sync/core.entity_form_display.node.vba_facility_service.default.yml +++ b/config/sync/core.entity_form_display.node.vba_facility_service.default.yml @@ -9,6 +9,7 @@ dependencies: - field.field.node.vba_facility_service.field_office - field.field.node.vba_facility_service.field_service_location - field.field.node.vba_facility_service.field_service_name_and_descripti + - field.field.node.vba_facility_service.field_vba_fac_serv_appt_default - node.type.vba_facility_service - workflows.workflow.editorial module: @@ -27,7 +28,7 @@ third_party_settings: label: 'Section settings' region: content parent_name: '' - weight: 6 + weight: 5 format_type: details_sidebar format_settings: classes: '' @@ -44,7 +45,7 @@ third_party_settings: label: 'Editorial workflow' region: content parent_name: '' - weight: 7 + weight: 6 format_type: fieldset format_settings: classes: '' @@ -98,7 +99,7 @@ content: third_party_settings: { } field_last_saved_by_an_editor: type: datetime_timestamp - weight: 10 + weight: 9 region: content settings: { } third_party_settings: { } @@ -150,7 +151,7 @@ content: third_party_settings: { } status: type: boolean_checkbox - weight: 8 + weight: 7 region: content settings: display_label: true @@ -164,12 +165,13 @@ content: placeholder: '' third_party_settings: { } url_redirects: - weight: 9 + weight: 8 region: content settings: { } third_party_settings: { } hidden: created: true + field_vba_fac_serv_appt_default: true langcode: true path: true promote: true diff --git a/config/sync/core.entity_form_display.node.vba_facility_service.inline_entity_form.yml b/config/sync/core.entity_form_display.node.vba_facility_service.inline_entity_form.yml index e8230ae056..81f67e6628 100644 --- a/config/sync/core.entity_form_display.node.vba_facility_service.inline_entity_form.yml +++ b/config/sync/core.entity_form_display.node.vba_facility_service.inline_entity_form.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.vba_facility_service.field_office - field.field.node.vba_facility_service.field_service_location - field.field.node.vba_facility_service.field_service_name_and_descripti + - field.field.node.vba_facility_service.field_vba_fac_serv_appt_default - node.type.vba_facility_service module: - field_group @@ -91,6 +92,7 @@ hidden: field_enforce_unique_combo: true field_last_saved_by_an_editor: true field_service_location: true + field_vba_fac_serv_appt_default: true langcode: true moderation_state: true path: true diff --git a/config/sync/core.entity_form_display.node.vha_facility_nonclinical_service.default.yml b/config/sync/core.entity_form_display.node.vha_facility_nonclinical_service.default.yml index aa6fc220ee..c839a23a3d 100644 --- a/config/sync/core.entity_form_display.node.vha_facility_nonclinical_service.default.yml +++ b/config/sync/core.entity_form_display.node.vha_facility_nonclinical_service.default.yml @@ -9,6 +9,7 @@ dependencies: - field.field.node.vha_facility_nonclinical_service.field_last_saved_by_an_editor - field.field.node.vha_facility_nonclinical_service.field_service_location - field.field.node.vha_facility_nonclinical_service.field_service_name_and_descripti + - field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default - node.type.vha_facility_nonclinical_service - workflows.workflow.editorial module: @@ -77,7 +78,7 @@ content: third_party_settings: { } field_last_saved_by_an_editor: type: datetime_timestamp - weight: 26 + weight: 8 region: content settings: { } third_party_settings: { } @@ -130,6 +131,7 @@ content: third_party_settings: { } hidden: created: true + field_vamc_nonclin_appt_default: true langcode: true promote: true status: true diff --git a/config/sync/core.entity_view_display.node.service_region.default.yml b/config/sync/core.entity_view_display.node.service_region.default.yml index a488c8f01b..6c92ff9c48 100644 --- a/config/sync/core.entity_view_display.node.service_region.default.yml +++ b/config/sync/core.entity_view_display.node.service_region.default.yml @@ -10,10 +10,12 @@ dependencies: - field.field.node.service_region.field_service_location - field.field.node.service_region.field_service_name_and_descripti - field.field.node.service_region.field_vba_region_facility_list + - field.field.node.service_region.field_vba_serv_reg_appt_default - node.type.service_region module: - entity_reference_revisions - field_group + - markup - user third_party_settings: field_group: @@ -92,6 +94,13 @@ content: third_party_settings: { } weight: 2 region: content + field_vba_serv_reg_appt_default: + type: markup + label: above + settings: { } + third_party_settings: { } + weight: 6 + region: content hidden: body: true breadcrumbs: true diff --git a/config/sync/core.entity_view_display.node.service_region.full.yml b/config/sync/core.entity_view_display.node.service_region.full.yml index cd7879a105..82e79ca765 100644 --- a/config/sync/core.entity_view_display.node.service_region.full.yml +++ b/config/sync/core.entity_view_display.node.service_region.full.yml @@ -11,6 +11,7 @@ dependencies: - field.field.node.service_region.field_service_location - field.field.node.service_region.field_service_name_and_descripti - field.field.node.service_region.field_vba_region_facility_list + - field.field.node.service_region.field_vba_serv_reg_appt_default - node.type.service_region module: - entity_reference_revisions @@ -120,6 +121,7 @@ hidden: body: true breadcrumbs: true content_moderation_control: true + field_vba_serv_reg_appt_default: true langcode: true links: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.service_region.teaser.yml b/config/sync/core.entity_view_display.node.service_region.teaser.yml index 812f580b10..ea7cb771a7 100644 --- a/config/sync/core.entity_view_display.node.service_region.teaser.yml +++ b/config/sync/core.entity_view_display.node.service_region.teaser.yml @@ -11,6 +11,7 @@ dependencies: - field.field.node.service_region.field_service_location - field.field.node.service_region.field_service_name_and_descripti - field.field.node.service_region.field_vba_region_facility_list + - field.field.node.service_region.field_vba_serv_reg_appt_default - node.type.service_region module: - text @@ -46,5 +47,6 @@ hidden: field_service_location: true field_service_name_and_descripti: true field_vba_region_facility_list: true + field_vba_serv_reg_appt_default: true langcode: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.vba_facility_service.default.yml b/config/sync/core.entity_view_display.node.vba_facility_service.default.yml index 26841c30a1..af293fe96c 100644 --- a/config/sync/core.entity_view_display.node.vba_facility_service.default.yml +++ b/config/sync/core.entity_view_display.node.vba_facility_service.default.yml @@ -9,10 +9,12 @@ dependencies: - field.field.node.vba_facility_service.field_office - field.field.node.vba_facility_service.field_service_location - field.field.node.vba_facility_service.field_service_name_and_descripti + - field.field.node.vba_facility_service.field_vba_fac_serv_appt_default - node.type.vba_facility_service module: - allow_only_one - entity_reference_revisions + - markup - user id: node.vba_facility_service.default targetEntityType: node @@ -51,6 +53,13 @@ content: third_party_settings: { } weight: 1 region: content + field_vba_fac_serv_appt_default: + type: markup + label: above + settings: { } + third_party_settings: { } + weight: 4 + region: content hidden: breadcrumbs: true content_moderation_control: true diff --git a/config/sync/core.entity_view_display.node.vba_facility_service.search_index.yml b/config/sync/core.entity_view_display.node.vba_facility_service.search_index.yml index 546d4ed7f4..6c4b30ea44 100644 --- a/config/sync/core.entity_view_display.node.vba_facility_service.search_index.yml +++ b/config/sync/core.entity_view_display.node.vba_facility_service.search_index.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.vba_facility_service.field_office - field.field.node.vba_facility_service.field_service_location - field.field.node.vba_facility_service.field_service_name_and_descripti + - field.field.node.vba_facility_service.field_vba_fac_serv_appt_default - node.type.vba_facility_service module: - allow_only_one @@ -53,6 +54,7 @@ hidden: field_administration: true field_last_saved_by_an_editor: true field_service_location: true + field_vba_fac_serv_appt_default: true langcode: true links: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.vba_facility_service.teaser.yml b/config/sync/core.entity_view_display.node.vba_facility_service.teaser.yml index a54411a0d5..006c9abd80 100644 --- a/config/sync/core.entity_view_display.node.vba_facility_service.teaser.yml +++ b/config/sync/core.entity_view_display.node.vba_facility_service.teaser.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.vba_facility_service.field_office - field.field.node.vba_facility_service.field_service_location - field.field.node.vba_facility_service.field_service_name_and_descripti + - field.field.node.vba_facility_service.field_vba_fac_serv_appt_default - node.type.vba_facility_service module: - user @@ -32,5 +33,6 @@ hidden: field_office: true field_service_location: true field_service_name_and_descripti: true + field_vba_fac_serv_appt_default: true langcode: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.default.yml b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.default.yml index af936ae78f..a4d4048abf 100644 --- a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.default.yml +++ b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.default.yml @@ -9,14 +9,23 @@ dependencies: - field.field.node.vha_facility_nonclinical_service.field_last_saved_by_an_editor - field.field.node.vha_facility_nonclinical_service.field_service_location - field.field.node.vha_facility_nonclinical_service.field_service_name_and_descripti + - field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default - node.type.vha_facility_nonclinical_service module: + - markup - user id: node.vha_facility_nonclinical_service.default targetEntityType: node bundle: vha_facility_nonclinical_service mode: default -content: { } +content: + field_vamc_nonclin_appt_default: + type: markup + label: above + settings: { } + third_party_settings: { } + weight: 1 + region: content hidden: breadcrumbs: true content_moderation_control: true diff --git a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.search_index.yml b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.search_index.yml index 01b1f75d19..7f00d08c8a 100644 --- a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.search_index.yml +++ b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.search_index.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.vha_facility_nonclinical_service.field_last_saved_by_an_editor - field.field.node.vha_facility_nonclinical_service.field_service_location - field.field.node.vha_facility_nonclinical_service.field_service_name_and_descripti + - field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default - node.type.vha_facility_nonclinical_service module: - allow_only_one @@ -48,6 +49,7 @@ hidden: field_facility_location: true field_last_saved_by_an_editor: true field_service_name_and_descripti: true + field_vamc_nonclin_appt_default: true langcode: true links: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.teaser.yml b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.teaser.yml index d52e9b5a64..6943cc5b2a 100644 --- a/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.teaser.yml +++ b/config/sync/core.entity_view_display.node.vha_facility_nonclinical_service.teaser.yml @@ -10,6 +10,7 @@ dependencies: - field.field.node.vha_facility_nonclinical_service.field_last_saved_by_an_editor - field.field.node.vha_facility_nonclinical_service.field_service_location - field.field.node.vha_facility_nonclinical_service.field_service_name_and_descripti + - field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default - node.type.vha_facility_nonclinical_service module: - user @@ -36,5 +37,6 @@ hidden: field_last_saved_by_an_editor: true field_service_location: true field_service_name_and_descripti: true + field_vamc_nonclin_appt_default: true langcode: true search_api_excerpt: true diff --git a/config/sync/field.field.node.service_region.field_vba_serv_reg_appt_default.yml b/config/sync/field.field.node.service_region.field_vba_serv_reg_appt_default.yml new file mode 100644 index 0000000000..e2d5acef11 --- /dev/null +++ b/config/sync/field.field.node.service_region.field_vba_serv_reg_appt_default.yml @@ -0,0 +1,28 @@ +uuid: 58ae6795-1dcb-4ff9-9dee-389f59676ba4 +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_vba_serv_reg_appt_default + - node.type.service_region + module: + - markup + - tmgmt_content +third_party_settings: + tmgmt_content: + excluded: false +id: node.service_region.field_vba_serv_reg_appt_default +field_name: field_vba_serv_reg_appt_default +entity_type: node +bundle: service_region +label: 'Appointment lead-in default' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + markup: + value: '
Contact us to schedule, reschedule, or cancel your appointment at our service region.
' + format: rich_text +field_type: markup diff --git a/config/sync/field.field.node.vba_facility_service.field_vba_fac_serv_appt_default.yml b/config/sync/field.field.node.vba_facility_service.field_vba_fac_serv_appt_default.yml new file mode 100644 index 0000000000..f9f05424d2 --- /dev/null +++ b/config/sync/field.field.node.vba_facility_service.field_vba_fac_serv_appt_default.yml @@ -0,0 +1,28 @@ +uuid: 6a047608-0392-4784-987f-ebe107cddf8a +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_vba_fac_serv_appt_default + - node.type.vba_facility_service + module: + - markup + - tmgmt_content +third_party_settings: + tmgmt_content: + excluded: false +id: node.vba_facility_service.field_vba_fac_serv_appt_default +field_name: field_vba_fac_serv_appt_default +entity_type: node +bundle: vba_facility_service +label: 'Appointment lead-in default' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + markup: + value: 'Contact us to schedule, reschedule, or cancel your appointment.
' + format: rich_text +field_type: markup diff --git a/config/sync/field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default.yml b/config/sync/field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default.yml new file mode 100644 index 0000000000..d637a40567 --- /dev/null +++ b/config/sync/field.field.node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default.yml @@ -0,0 +1,28 @@ +uuid: 84e6b6e5-56e6-4f90-8402-e549c0cd9030 +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_vamc_nonclin_appt_default + - node.type.vha_facility_nonclinical_service + module: + - markup + - tmgmt_content +third_party_settings: + tmgmt_content: + excluded: false +id: node.vha_facility_nonclinical_service.field_vamc_nonclin_appt_default +field_name: field_vamc_nonclin_appt_default +entity_type: node +bundle: vha_facility_nonclinical_service +label: 'Appointment lead-in default' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + markup: + value: 'Contact us to schedule, reschedule, or cancel your appointment.
' + format: rich_text +field_type: markup diff --git a/config/sync/field.storage.node.field_vamc_nonclin_appt_default.yml b/config/sync/field.storage.node.field_vamc_nonclin_appt_default.yml new file mode 100644 index 0000000000..11ffb81775 --- /dev/null +++ b/config/sync/field.storage.node.field_vamc_nonclin_appt_default.yml @@ -0,0 +1,19 @@ +uuid: f892fada-be3e-4019-9bb7-eb23cc7735be +langcode: en +status: true +dependencies: + module: + - markup + - node +id: node.field_vamc_nonclin_appt_default +field_name: field_vamc_nonclin_appt_default +entity_type: node +type: markup +settings: { } +module: markup +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/sync/field.storage.node.field_vba_fac_serv_appt_default.yml b/config/sync/field.storage.node.field_vba_fac_serv_appt_default.yml new file mode 100644 index 0000000000..43546b83ca --- /dev/null +++ b/config/sync/field.storage.node.field_vba_fac_serv_appt_default.yml @@ -0,0 +1,19 @@ +uuid: 40df6edc-0ab0-4d7c-9646-25a05172fff9 +langcode: en +status: true +dependencies: + module: + - markup + - node +id: node.field_vba_fac_serv_appt_default +field_name: field_vba_fac_serv_appt_default +entity_type: node +type: markup +settings: { } +module: markup +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/sync/field.storage.node.field_vba_serv_reg_appt_default.yml b/config/sync/field.storage.node.field_vba_serv_reg_appt_default.yml new file mode 100644 index 0000000000..4608ca20db --- /dev/null +++ b/config/sync/field.storage.node.field_vba_serv_reg_appt_default.yml @@ -0,0 +1,19 @@ +uuid: 535ddded-64f2-491e-bb21-dd21d13f686f +langcode: en +status: true +dependencies: + module: + - markup + - node +id: node.field_vba_serv_reg_appt_default +field_name: field_vba_serv_reg_appt_default +entity_type: node +type: markup +settings: { } +module: markup +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/docroot/modules/custom/va_gov_backend/va_gov_backend.module b/docroot/modules/custom/va_gov_backend/va_gov_backend.module index 166de635c3..b11d1749b5 100644 --- a/docroot/modules/custom/va_gov_backend/va_gov_backend.module +++ b/docroot/modules/custom/va_gov_backend/va_gov_backend.module @@ -380,12 +380,6 @@ function va_gov_backend_form_alter(&$form, FormStateInterface $form_state, $form $form['description']['widget']['#after_build'][] = '_va_gov_backend_allowed_formats_remove_textarea_help'; } - if (isset($form['field_hservice_appt_intro_select'])) { - $form['field_hservice_appt_leadin']['widget'][0]['value']['#title_display'] = 'invisible'; - _va_gov_backend_modify_appt_intro_text_states($form, $form_state); - $form['#validate'][] = '_va_gov_backend_appt_intro_text_validation'; - } - // Disable path alias modification after lc node is published. _va_gov_backend_disable_alias_widget($form, $form_state); @@ -609,39 +603,6 @@ function va_gov_backend_entity_view_alter(array &$build, EntityInterface $entity } } - // Check if correct content bundle and unset fields. - if ($entity instanceof FieldableEntityInterface && $entity->getEntityTypeId() === 'node' && $entity->bundle() === 'health_care_local_health_service') { - foreach (_va_gov_backend_unset_fields($entity) as $appt_intro_field) { - unset($build[$appt_intro_field]); - } - }; - -} - -/** - * Returns the fields that need to be unset. - * - * @return array - * Fields that should be unset. - */ -function _va_gov_backend_unset_fields(FieldableEntityInterface $entity) { - $appt_intro_select = $entity->get('field_hservice_appt_intro_select')->value; - if ($appt_intro_select === 'default_intro_text') { - return [ - 'field_hservice_appt_leadin', - ]; - } - elseif ($appt_intro_select === 'custom_intro_text') { - return [ - 'field_hservices_lead_in_default', - ]; - } - else { - return [ - 'field_hservices_lead_in_default', - 'field_hservice_appt_leadin', - ]; - } } /** @@ -656,49 +617,6 @@ function _va_gov_backend_get_unlocked_alias_bundles() { return ['documentation_page']; } -/** - * Visibility of Appointment Lead-in Text field. - * - * @param array $form - * The node form array. - * @param Drupal\Core\Form\FormStateInterface $form_state - * Instance of FormStateInterface. - */ -function _va_gov_backend_modify_appt_intro_text_states(array &$form, FormStateInterface $form_state) { - if (isset($form['field_hservice_appt_intro_select'])) { - $form['field_hservice_appt_leadin']['#states'] = [ - 'visible' => [ - ':input[name="field_hservice_appt_intro_select"]' => ['value' => 'custom_intro_text'], - ], - ]; - $form['field_hservices_lead_in_default']['#states'] = [ - 'visible' => [ - ':input[name="field_hservice_appt_intro_select"]' => ['value' => 'default_intro_text'], - ], - ]; - } -} - -/** - * Adds Validation to check for an empty Appointment lead-in field. - * - * @param array $form - * The exposed widget form array. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state. - */ -function _va_gov_backend_appt_intro_text_validation(array $form, FormStateInterface $form_state) { - if (!empty($form_state->getValue('field_hservice_appt_leadin')) && !empty($form_state->getValue('field_hservice_appt_intro_select'))) { - $intro_type = $form_state->getValue('field_hservice_appt_intro_select'); - $intro_text_value = $form_state->getValue('field_hservice_appt_leadin'); - if ($intro_type[0]['value'] === 'custom_intro_text') { - if (($intro_text_value[0]['value'] === "")) { - $form_state->setErrorByName("field_hservice_appt_leadin", t('Appointment lead-in text required')); - } - } - } -} - /** * Disable url alias widget after publish. * diff --git a/docroot/modules/custom/va_gov_facilities/src/EventSubscriber/FacilitiesSubscriber.php b/docroot/modules/custom/va_gov_facilities/src/EventSubscriber/FacilitiesSubscriber.php index c2f58d0a6a..90e97dee22 100644 --- a/docroot/modules/custom/va_gov_facilities/src/EventSubscriber/FacilitiesSubscriber.php +++ b/docroot/modules/custom/va_gov_facilities/src/EventSubscriber/FacilitiesSubscriber.php @@ -22,6 +22,7 @@ use Drupal\field_event_dispatcher\Event\Field\WidgetCompleteFormAlterEvent; use Drupal\field_event_dispatcher\FieldHookEvents; use Drupal\node\NodeInterface; +use Drupal\paragraphs\ParagraphInterface; use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -161,7 +162,9 @@ public static function createRenderArrayFromFieldOnRefdEntity(NodeInterface $nod */ public function entityPresave(EntityPresaveEvent $event): void { $entity = $event->getEntity(); + $this->clearCustomAppointmentIntroText($entity); $this->clearNormalStatusDetails($entity); + $this->clearUnusedServiceLocationHours($entity); } /** @@ -297,6 +300,51 @@ private function getFacilityHours(array &$widget_complete_form, FormStateInterfa } } + /** + * Clear custom appointment intro text when unused. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * Entity. + */ + protected function clearCustomAppointmentIntroText(EntityInterface $entity): void { + if ($entity instanceof ParagraphInterface) { + $type = $entity->getType(); + /** @var \Drupal\paragraphs\ParagraphInterface $entity */ + if (($type === 'service_location') + && ($entity->hasField('field_appt_intro_text_type')) + && ($entity->hasField('field_appt_intro_text_custom'))) { + $appt_select = $entity->get('field_appt_intro_text_type')->value; + $appt_leadin = $entity->get('field_appt_intro_text_custom')->value; + if ($appt_select !== 'customize_text' && !empty($appt_leadin)) { + $entity->set('field_appt_intro_text_custom', ''); + } + } + } + } + + /** + * Clear service location hours when unused. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * Entity. + */ + protected function clearUnusedServiceLocationHours(EntityInterface $entity): void { + if ($entity instanceof ParagraphInterface) { + $type = $entity->getType(); + /** @var \Drupal\paragraphs\ParagraphInterface $entity */ + if (($type === 'service_location') + && ($entity->hasField('field_hours')) + && ($entity->hasField('field_office_hours'))) { + $hours = $entity->get('field_hours')->value; + $office_hours = $entity->get('field_office_hours')->getValue(); + // 2 = Provide specific hours for this service. + if ($hours !== '2' && count($office_hours) > 0) { + $entity->set('field_office_hours', []); + } + } + } + } + /** * Clear status details when operating status is normal. * diff --git a/docroot/modules/custom/va_gov_facilities/va_gov_facilities.info.yml b/docroot/modules/custom/va_gov_facilities/va_gov_facilities.info.yml index 1034cbc4ed..0f1edb4b7b 100644 --- a/docroot/modules/custom/va_gov_facilities/va_gov_facilities.info.yml +++ b/docroot/modules/custom/va_gov_facilities/va_gov_facilities.info.yml @@ -3,3 +3,5 @@ type: module description: 'Tools to improve user experience for VA Facilities.' core_version_requirement: ^9 || ^10 package: 'Custom' +dependencies: + - va_gov_backend \ No newline at end of file diff --git a/docroot/modules/custom/va_gov_facilities/va_gov_facilities.module b/docroot/modules/custom/va_gov_facilities/va_gov_facilities.module index 60104d5049..12079ee8f2 100644 --- a/docroot/modules/custom/va_gov_facilities/va_gov_facilities.module +++ b/docroot/modules/custom/va_gov_facilities/va_gov_facilities.module @@ -5,6 +5,9 @@ * Contains va_gov_facilities.module. */ +use Drupal\Component\Render\FormattableMarkup; + +use Drupal\Core\Form\FormStateInterface; use Drupal\va_gov_facilities\EventSubscriber\FacilitiesSubscriber; /** @@ -38,3 +41,71 @@ function va_gov_facilities_preprocess_field__paragraph__field_hours(&$variables) } } } + +/** + * Populates Service Location form with default appointment text from service. + * + * @param Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * + * @return string + * The default appointment text from the service node type. + */ +function _va_gov_facilities_populate_service_default_appt_text(FormStateInterface $form_state): string { + $default_text = ''; + /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */ + $form_object = $form_state->getFormObject(); + $bundle = $form_object->getEntity()->bundle(); + $entity = $form_object->getEntity(); + $service_types = [ + 'health_care_local_health_service' => 'field_hservices_lead_in_default', + 'service_region' => 'field_vba_serv_reg_appt_default', + 'vba_facility_service' => 'field_vba_fac_serv_appt_default', + 'vha_facility_nonclinical_service' => 'field_vamc_nonclin_appt_default', + ]; + foreach ($service_types as $service_type => $default_field) { + if ($bundle === $service_type) { + if ($entity->$default_field && !$entity->$default_field->isEmpty()) { + $default_text = trim(strip_tags($entity->$default_field->getFieldDefinition()->getSetting('markup')['value'])); + } + } + } + + return $default_text; +} + +/** + * Implements hook_field_widget_single_element_WIDGET_TYPE_form_alter(). + */ +function va_gov_facilities_field_widget_single_element_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) { + $paragraph_type = $element['#paragraph_type'] ?? ''; + if ($paragraph_type === 'service_location') { + // Set the default text for appointments. + $default_text = _va_gov_facilities_populate_service_default_appt_text($form_state) ?? ''; + $description = new FormattableMarkup($default_text, []); + // Create the form element for the default text for appointments. + // Nest it under the select list about the type of text. + $element['subform']['field_appt_intro_text_type']['temp_default_text'] = [ + '#type' => 'textarea', + '#title' => t('Default text'), + '#value' => $description, + '#weight' => 1, + '#disabled' => TRUE, + ]; + // Hide appointments custom text unless explicitly selected. + $selector = sprintf(':input[name="field_service_location[%d][subform][field_appt_intro_text_type]"]', $element['#delta']); + // The default appointment text shows as a disabled form element. + $element['subform']['field_appt_intro_text_type']['temp_default_text']['#states'] = [ + 'visible' => [ + $selector => ['value' => 'use_default_text'], + ], + ]; + $element['subform']['field_appt_intro_text_custom']['#states'] = [ + 'visible' => [ + $selector => ['value' => 'customize_text'], + ], + ]; + + } + +} diff --git a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php index 4b4151fb16..4624ba15ab 100644 --- a/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_vamc/src/EventSubscriber/VAMCEntityEventSubscriber.php @@ -14,7 +14,6 @@ use Drupal\core_event_dispatcher\Event\Entity\EntityViewAlterEvent; use Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent; use Drupal\node\NodeInterface; -use Drupal\paragraphs\ParagraphInterface; use Drupal\va_gov_notifications\Service\NotificationsManager; use Drupal\va_gov_user\Service\UserPermsService; use Drupal\va_gov_vamc\Service\ContentHardeningDeduper; @@ -156,8 +155,6 @@ public function entityViewAlter(EntityViewAlterEvent $event):void { public function entityPresave(EntityPresaveEvent $event): void { $entity = $event->getEntity(); $this->contentHardeningDeduper->removeDuplicate($entity); - $this->clearCustomAppointmentIntroText($entity); - $this->clearUnusedServiceLocationHours($entity); } /** @@ -335,51 +332,6 @@ public function alterRegionalHealthCareServiceDesNodeForm(FormIdAlterEvent $even $form['#attached']['library'][] = 'va_gov_vamc/limit_vamcs_to_workbench'; } - /** - * Clear custom appointment intro text when unused. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * Entity. - */ - protected function clearCustomAppointmentIntroText(EntityInterface $entity): void { - if ($entity instanceof NodeInterface) { - $bundle = $entity->bundle(); - /** @var \Drupal\node\NodeInterface $entity */ - if (($bundle === 'health_care_local_health_service') - && ($entity->hasField('field_hservice_appt_intro_select')) - && ($entity->hasField('field_hservice_appt_leadin'))) { - $appt_select = $entity->get('field_hservice_appt_intro_select')->value; - $appt_leadin = $entity->get('field_hservice_appt_leadin')->value; - if ($appt_select !== 'custom_intro_text' && !empty($appt_leadin)) { - $entity->set('field_hservice_appt_leadin', ''); - } - } - } - } - - /** - * Clear service location hours when unused. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * Entity. - */ - protected function clearUnusedServiceLocationHours(EntityInterface $entity): void { - if ($entity instanceof ParagraphInterface) { - $type = $entity->getType(); - /** @var \Drupal\paragraphs\ParagraphInterface $entity */ - if (($type === 'service_location') - && ($entity->hasField('field_hours')) - && ($entity->hasField('field_office_hours'))) { - $hours = $entity->get('field_hours')->value; - $office_hours = $entity->get('field_office_hours')->getValue(); - // 2 = Provide specific hours for this service. - if ($hours !== '2' && count($office_hours) > 0) { - $entity->set('field_office_hours', []); - } - } - } - } - /** * Shows the text "Unspecified" when phone number is blank. *