From ae92483a374e311b1c4be162f0bbab488ac5c17a Mon Sep 17 00:00:00 2001 From: Daniel Sasser Date: Tue, 24 Oct 2023 14:06:43 -0700 Subject: [PATCH] VACMS-15641 national outreach checkbox (#15761) * VACMS-10089: Outreach checkbox without field listing cardinality change * VACMS-10089: The piece we need to rethink * VACMS-15641: Adds check for approved outreach checkbox users. * VACMS-15641: Uses new field for storing additional event listings. * VACMS-15641: Adds new field, field_additional_listings to the Event content type. * VACMS-15641: Restores revision_log to the events form display. * VACMS-15641: Allows admins to see the checkbox. * VACMS-15641: Ensure the additional listings are removed if the checkbox is unchecked. * VACMS-15641: Updates events cypress test. - Changes the feature toggle step definition to not require admin. * VACMS-15641: Remove an unnecessary cypress test. * VACMS-15641: Remove redundant test. --------- Co-authored-by: Christia Troyer Co-authored-by: Daniel Sasser --- ...entity_form_display.node.event.default.yml | 37 ++- ...entity_view_display.node.event.default.yml | 53 ++++- ....entity_view_display.node.event.teaser.yml | 16 ++ config/sync/feature_toggle.features.yml | 1 + ...d.node.event.field_additional_listings.yml | 38 ++++ ...de.event.field_publish_to_outreach_cal.yml | 28 +++ ...storage.node.field_additional_listings.yml | 19 ++ ...age.node.field_publish_to_outreach_cal.yml | 18 ++ .../EventSubscriber/EntityEventSubscriber.php | 213 +++++++++++++++++- .../va_gov_events/va_gov_events.services.yml | 2 +- .../assets/scss/components/_fields.scss | 8 + .../features/content_type/event.feature | 12 +- .../features/platform/file_upload.feature | 11 - .../common/i_create_a_node.js | 2 + .../common/i_set_a_feature_toggle.js | 14 ++ tests/cypress/support/commands.js | 8 + 16 files changed, 431 insertions(+), 49 deletions(-) create mode 100644 config/sync/field.field.node.event.field_additional_listings.yml create mode 100644 config/sync/field.field.node.event.field_publish_to_outreach_cal.yml create mode 100644 config/sync/field.storage.node.field_additional_listings.yml create mode 100644 config/sync/field.storage.node.field_publish_to_outreach_cal.yml delete mode 100644 tests/cypress/integration/features/platform/file_upload.feature create mode 100644 tests/cypress/integration/step_definitions/common/i_set_a_feature_toggle.js diff --git a/config/sync/core.entity_form_display.node.event.default.yml b/config/sync/core.entity_form_display.node.event.default.yml index 8c99f87f35..a5a1bb89ee 100644 --- a/config/sync/core.entity_form_display.node.event.default.yml +++ b/config/sync/core.entity_form_display.node.event.default.yml @@ -4,6 +4,7 @@ status: true dependencies: config: - field.field.node.event.field_additional_information_abo + - field.field.node.event.field_additional_listings - field.field.node.event.field_address - field.field.node.event.field_administration - field.field.node.event.field_body @@ -23,6 +24,7 @@ dependencies: - field.field.node.event.field_media - field.field.node.event.field_meta_tags - field.field.node.event.field_order + - field.field.node.event.field_publish_to_outreach_cal - field.field.node.event.field_url_of_an_online_event - node.type.event - workflows.workflow.editorial @@ -46,7 +48,7 @@ third_party_settings: label: 'Section settings' region: content parent_name: '' - weight: 8 + weight: 9 format_type: details_sidebar format_settings: classes: '' @@ -64,7 +66,7 @@ third_party_settings: label: Location region: content parent_name: '' - weight: 7 + weight: 8 format_type: details format_settings: classes: '' @@ -81,7 +83,7 @@ third_party_settings: label: Registration region: content parent_name: '' - weight: 6 + weight: 7 format_type: fieldset format_settings: classes: '' @@ -142,7 +144,7 @@ third_party_settings: label: 'Meta Tags' region: content parent_name: '' - weight: 5 + weight: 6 format_type: fieldset format_settings: classes: '' @@ -173,7 +175,7 @@ third_party_settings: label: Free region: content parent_name: group_all_events_are_free - weight: 15 + weight: 32 format_type: html_element format_settings: classes: '' @@ -200,7 +202,7 @@ content: third_party_settings: { } field_additional_information_abo: type: text_textarea - weight: 31 + weight: 32 region: content settings: rows: 5 @@ -220,7 +222,7 @@ content: third_party_settings: { } field_body: type: text_textarea - weight: 4 + weight: 5 region: content settings: rows: 5 @@ -258,7 +260,10 @@ content: custom show_extra: true hide_date: false + separator: to add_abbreviations: '' + allday: true + remove_seconds: false third_party_settings: smart_date_recur: modal: true @@ -318,7 +323,7 @@ content: third_party_settings: { } field_last_saved_by_an_editor: type: datetime_timestamp - weight: 44 + weight: 16 region: content settings: { } third_party_settings: { } @@ -337,7 +342,11 @@ content: weight: 2 region: content settings: { } - third_party_settings: { } + third_party_settings: + limited_field_widgets: + limit_values: '1' + change_labels: + add_another: '' field_location_humanreadable: type: string_textfield weight: 16 @@ -354,7 +363,7 @@ content: third_party_settings: { } field_media: type: media_library_widget - weight: 3 + weight: 4 region: content settings: media_types: { } @@ -365,6 +374,13 @@ content: region: content settings: { } third_party_settings: { } + field_publish_to_outreach_cal: + type: boolean_checkbox + weight: 3 + region: content + settings: + display_label: true + third_party_settings: { } field_url_of_an_online_event: type: linkit weight: 15 @@ -411,6 +427,7 @@ content: settings: { } third_party_settings: { } hidden: + field_additional_listings: true field_event_cost: true field_meta_tags: true langcode: true diff --git a/config/sync/core.entity_view_display.node.event.default.yml b/config/sync/core.entity_view_display.node.event.default.yml index c765795f38..9dce9c4eb3 100644 --- a/config/sync/core.entity_view_display.node.event.default.yml +++ b/config/sync/core.entity_view_display.node.event.default.yml @@ -4,6 +4,7 @@ status: true dependencies: config: - field.field.node.event.field_additional_information_abo + - field.field.node.event.field_additional_listings - field.field.node.event.field_address - field.field.node.event.field_administration - field.field.node.event.field_body @@ -23,6 +24,7 @@ dependencies: - field.field.node.event.field_media - field.field.node.event.field_meta_tags - field.field.node.event.field_order + - field.field.node.event.field_publish_to_outreach_cal - field.field.node.event.field_url_of_an_online_event - node.type.event module: @@ -50,6 +52,8 @@ third_party_settings: group_c: children: - field_datetime_range_timezone + - field_listing + - field_additional_listings - field_media - field_body - field_url_of_an_online_event @@ -74,7 +78,7 @@ third_party_settings: label: Location-related parent_name: group_c region: content - weight: 28 + weight: 8 format_type: fieldset format_settings: classes: '' @@ -89,7 +93,7 @@ third_party_settings: label: 'Registration related' parent_name: group_c region: content - weight: 29 + weight: 9 format_type: fieldset format_settings: classes: '' @@ -120,7 +124,15 @@ content: label: above settings: { } third_party_settings: { } - weight: 29 + weight: 21 + region: content + field_additional_listings: + type: entity_reference_label + label: above + settings: + link: true + third_party_settings: { } + weight: 3 region: content field_address: type: address_default @@ -134,7 +146,7 @@ content: label: above settings: { } third_party_settings: { } - weight: 25 + weight: 5 region: content field_datetime_range_timezone: type: smartdate_default @@ -146,8 +158,17 @@ content: force_chronological: false add_classes: false time_wrapper: true + localize: false + parts: + - start + - end + duration: + separator: ' | ' + unit: '' + decimals: 2 + suffix: h third_party_settings: { } - weight: 23 + weight: 1 region: content field_description: type: string @@ -163,14 +184,14 @@ content: settings: link_to_entity: false third_party_settings: { } - weight: 20 + weight: 19 region: content field_event_cta: type: list_default label: above settings: { } third_party_settings: { } - weight: 27 + weight: 7 region: content field_event_registrationrequired: type: boolean @@ -188,7 +209,7 @@ content: settings: link: true third_party_settings: { } - weight: 17 + weight: 18 region: content field_featured: type: boolean @@ -222,6 +243,14 @@ content: third_party_settings: { } weight: 17 region: content + field_listing: + type: entity_reference_label + label: above + settings: + link: true + third_party_settings: { } + weight: 2 + region: content field_location_humanreadable: type: string label: above @@ -235,7 +264,7 @@ content: label: above settings: { } third_party_settings: { } - weight: 16 + weight: 17 region: content field_media: type: entity_reference_entity_view @@ -244,7 +273,7 @@ content: view_mode: default link: false third_party_settings: { } - weight: 24 + weight: 4 region: content field_order: type: list_default @@ -263,15 +292,15 @@ content: rel: '' target: '' third_party_settings: { } - weight: 26 + weight: 6 region: content hidden: breadcrumbs: true content_moderation_control: true field_administration: true field_last_saved_by_an_editor: true - field_listing: true field_meta_tags: true + field_publish_to_outreach_cal: true langcode: true links: true search_api_excerpt: true diff --git a/config/sync/core.entity_view_display.node.event.teaser.yml b/config/sync/core.entity_view_display.node.event.teaser.yml index b2e2adfdd9..5ac4b47b0a 100644 --- a/config/sync/core.entity_view_display.node.event.teaser.yml +++ b/config/sync/core.entity_view_display.node.event.teaser.yml @@ -5,6 +5,7 @@ dependencies: config: - core.entity_view_mode.node.teaser - field.field.node.event.field_additional_information_abo + - field.field.node.event.field_additional_listings - field.field.node.event.field_address - field.field.node.event.field_administration - field.field.node.event.field_body @@ -24,6 +25,7 @@ dependencies: - field.field.node.event.field_media - field.field.node.event.field_meta_tags - field.field.node.event.field_order + - field.field.node.event.field_publish_to_outreach_cal - field.field.node.event.field_url_of_an_online_event - node.type.event module: @@ -35,6 +37,18 @@ targetEntityType: node bundle: event mode: teaser content: + breadcrumbs: + type: link + label: hidden + settings: + trim_length: 80 + url_only: false + url_plain: false + rel: '' + target: '' + third_party_settings: { } + weight: -5 + region: content field_body: type: text_default label: hidden @@ -56,6 +70,7 @@ content: hidden: content_moderation_control: true field_additional_information_abo: true + field_additional_listings: true field_address: true field_administration: true field_description: true @@ -73,6 +88,7 @@ hidden: field_media: true field_meta_tags: true field_order: true + field_publish_to_outreach_cal: true field_url_of_an_online_event: true langcode: true links: true diff --git a/config/sync/feature_toggle.features.yml b/config/sync/feature_toggle.features.yml index 3c70f0d3ef..500db73770 100644 --- a/config/sync/feature_toggle.features.yml +++ b/config/sync/feature_toggle.features.yml @@ -5,3 +5,4 @@ features: feature_single_value_field_link: FEATURE_SINGLE_VALUE_FIELD_LINK feature_health_connect_number: FEATURE_HEALTH_CONNECT_NUMBER feature_mobile_app_promo: FEATURE_MOBILE_APP_PROMO + feature_event_outreach_checkbox: FEATURE_EVENT_OUTREACH_CHECKBOX diff --git a/config/sync/field.field.node.event.field_additional_listings.yml b/config/sync/field.field.node.event.field_additional_listings.yml new file mode 100644 index 0000000000..7cad338854 --- /dev/null +++ b/config/sync/field.field.node.event.field_additional_listings.yml @@ -0,0 +1,38 @@ +uuid: 8a728072-bd70-4a45-9109-34daa8451ae8 +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_additional_listings + - node.type.event + module: + - entity_reference_validators + - tmgmt_content +third_party_settings: + entity_reference_validators: + circular_reference: false + circular_reference_deep: false + duplicate_reference: false + tmgmt_content: + excluded: false +id: node.event.field_additional_listings +field_name: field_additional_listings +entity_type: node +bundle: event +label: 'Additional Listings' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:node' + handler_settings: + target_bundles: + event: event + sort: + field: _none + direction: ASC + auto_create: false + auto_create_bundle: '' +field_type: entity_reference diff --git a/config/sync/field.field.node.event.field_publish_to_outreach_cal.yml b/config/sync/field.field.node.event.field_publish_to_outreach_cal.yml new file mode 100644 index 0000000000..297adec89e --- /dev/null +++ b/config/sync/field.field.node.event.field_publish_to_outreach_cal.yml @@ -0,0 +1,28 @@ +uuid: ba2d9d43-c4b9-4bfd-831a-9ef7544d43f8 +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_publish_to_outreach_cal + - node.type.event + module: + - tmgmt_content +third_party_settings: + tmgmt_content: + excluded: false +id: node.event.field_publish_to_outreach_cal +field_name: field_publish_to_outreach_cal +entity_type: node +bundle: event +label: 'Publish to the National Outreach Calendar' +description: '' +required: false +translatable: false +default_value: + - + value: 0 +default_value_callback: '' +settings: + on_label: 'Yes' + off_label: 'No' +field_type: boolean diff --git a/config/sync/field.storage.node.field_additional_listings.yml b/config/sync/field.storage.node.field_additional_listings.yml new file mode 100644 index 0000000000..f66f010832 --- /dev/null +++ b/config/sync/field.storage.node.field_additional_listings.yml @@ -0,0 +1,19 @@ +uuid: b7f382fa-a73c-4bdd-b7f7-4f4c1c0294e8 +langcode: en +status: true +dependencies: + module: + - node +id: node.field_additional_listings +field_name: field_additional_listings +entity_type: node +type: entity_reference +settings: + target_type: node +module: core +locked: false +cardinality: -1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/sync/field.storage.node.field_publish_to_outreach_cal.yml b/config/sync/field.storage.node.field_publish_to_outreach_cal.yml new file mode 100644 index 0000000000..760a11b0f3 --- /dev/null +++ b/config/sync/field.storage.node.field_publish_to_outreach_cal.yml @@ -0,0 +1,18 @@ +uuid: ad80a854-7f29-45c1-871a-2d087663f64a +langcode: en +status: true +dependencies: + module: + - node +id: node.field_publish_to_outreach_cal +field_name: field_publish_to_outreach_cal +entity_type: node +type: boolean +settings: { } +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/docroot/modules/custom/va_gov_events/src/EventSubscriber/EntityEventSubscriber.php b/docroot/modules/custom/va_gov_events/src/EventSubscriber/EntityEventSubscriber.php index b3a543ceed..4abaedfd52 100644 --- a/docroot/modules/custom/va_gov_events/src/EventSubscriber/EntityEventSubscriber.php +++ b/docroot/modules/custom/va_gov_events/src/EventSubscriber/EntityEventSubscriber.php @@ -2,9 +2,15 @@ namespace Drupal\va_gov_events\EventSubscriber; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Session\AccountProxy; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\core_event_dispatcher\EntityHookEvents; +use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent; use Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent; +use Drupal\feature_toggle\FeatureStatus; +use Drupal\node\NodeInterface; +use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -14,14 +20,89 @@ class EntityEventSubscriber implements EventSubscriberInterface { use StringTranslationTrait; + /** + * The 'publish to the national outreach calendar' field name. + */ + const PUBLISH_TO_OUTREACH_CAL_FIELD = 'field_publish_to_outreach_cal'; + + /** + * The 'field_listing' field name. + */ + const LISTING_FIELD = 'field_listing'; + + /** + * The 'field_additional_listings' field name. + */ + const ADDITIONAL_LISTING_FIELD = 'field_additional_listings'; + + /** + * The National Outreach Calendar node id. + */ + const OUTREACH_CAL_NID = 736; + + /** + * The 'Outreach Hub' Section term id. + */ + const OUTREACH_HUB_TID = 7; + + /** + * The Feature toggle name for outreach checkbox. + */ + const OUTREACH_CHECKBOX_FEATURE_NAME = 'feature_event_outreach_checkbox'; + + /** + * The list of users allowed to view the outreach checkbox. + */ + const OUTREACH_CHECKBOX_TEST_USERS = [ + 2910, + 1448, + 4356, + 2861, + 2922, + 3421, + 3314, + 4573, + 3864, + 1583, + 3610, + 2927, + ]; + + /** + * The User Perms Service. + * + * @var \Drupal\va_gov_user\Service\UserPermsService + */ + protected UserPermsService $userPermsService; + + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected AccountInterface $currentUser; + + /** + * TRUE if the outreach checkbox feature toggle is enabled. + * + * @var bool + */ + private bool $outreachCheckboxFeatureEnabled; + /** * Constructs the EventSubscriber object. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation service. + * @param \Drupal\va_gov_user\Service\UserPermsService $user_perms_service + * The current user perms service. + * @param \Drupal\Core\Session\AccountProxy $account_proxy + * The account proxy service. + * @param \Drupal\feature_toggle\FeatureStatus $feature_status + * The feature status service. */ - public function __construct(TranslationInterface $string_translation) { - $this->stringTranslation = $string_translation; + public function __construct(UserPermsService $user_perms_service, AccountProxy $account_proxy, FeatureStatus $feature_status) { + $this->userPermsService = $user_perms_service; + $this->currentUser = $account_proxy->getAccount(); + $this->outreachCheckboxFeatureEnabled = $feature_status->getStatus(self::OUTREACH_CHECKBOX_FEATURE_NAME); } /** @@ -31,11 +112,55 @@ public static function getSubscribedEvents(): array { return [ 'hook_event_dispatcher.form_node_event_form.alter' => 'alterEventNodeForm', 'hook_event_dispatcher.form_node_event_edit_form.alter' => 'alterEventNodeForm', + EntityHookEvents::ENTITY_PRE_SAVE => 'entityPresave', ]; } /** - * Form alterations for eventcontent type. + * Determines if the 'add to National Outreach Calendar' checkbox is enabled. + * + * @return bool + * TRUE if the outreach checkbox should be enabled. + */ + protected function outreachCheckboxEnabled(): bool { + $admin = $this->userPermsService->hasAdminRole(TRUE); + return ( + $this->outreachCheckboxFeatureEnabled + && (in_array($this->currentUser->id(), self::OUTREACH_CHECKBOX_TEST_USERS) || $admin) + ); + } + + /** + * Determines if the current user is an 'Outreach Hub' only user. + * + * @return bool + * TRUE if the current user only has the 'Outreach Hub' section. + */ + protected function outreachHubOnlyUser(): bool { + $sections = $this->userPermsService->getSections($this->currentUser); + if (count($sections) === 1 && array_key_first($sections) === self::OUTREACH_HUB_TID) { + return TRUE; + } + return FALSE; + } + + /** + * Entity presave Event call. + * + * @param \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event + * The event. + * + * @throws \Drupal\Core\TypedData\Exception\MissingDataException + */ + public function entityPresave(EntityPresaveEvent $event): void { + $entity = $event->getEntity(); + if ($entity instanceof NodeInterface) { + $this->addToNationalOutreachCalendar($entity); + } + } + + /** + * Form alterations for event content type. * * @param \Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent $event * The event. @@ -45,6 +170,76 @@ public function alterEventNodeForm(FormIdAlterEvent $event): void { $this->addDisplayManagementToEventFields($form); $this->modifyFormFieldsetElements($form); $this->modifyRecurringEventsWidgetFieldPresentation($form); + $this->modifyAddToOutreachCalendarElements($form); + } + + /** + * Adds the event to the National Outreach Calendar (event_listing). + * + * The purpose of this method is to add the current node event to the National + * Outreach Calendar (an event listing node) if the $listingField + * checkbox/boolean has been set, or if the current user is an Outreach Hub + * user. + * + * @param \Drupal\node\NodeInterface $node + * The node to be modified. + * + * @throws \Drupal\Core\TypedData\Exception\MissingDataException + */ + public function addToNationalOutreachCalendar(NodeInterface $node): void { + if ($node->hasField(self::LISTING_FIELD) && + $node->hasField(self::PUBLISH_TO_OUTREACH_CAL_FIELD) && + $node->hasField(self::ADDITIONAL_LISTING_FIELD) && + $this->outreachCheckboxEnabled()) { + $addToCalValue = $node->get(self::PUBLISH_TO_OUTREACH_CAL_FIELD)->first()->getValue(); + if (isset($addToCalValue['value'])) { + $listings = $node->get(self::LISTING_FIELD)->getValue(); + $additionalListings = $node->get(self::ADDITIONAL_LISTING_FIELD)->getValue(); + if ($addToCalValue['value'] === 1 || $this->outreachHubOnlyUser()) { + // Add to Outreach calendar selected, or user is Outreach Hub only + // user. + if (!in_array(self::OUTREACH_CAL_NID, array_column($listings + $additionalListings, 'target_id'))) { + $additionalListings[] = [ + 'target_id' => self::OUTREACH_CAL_NID, + ]; + } + } + else { + // Checkbox is unset. Ensure that additional listings are removed. + $additionalListings = []; + } + $node->set(self::ADDITIONAL_LISTING_FIELD, $additionalListings); + } + } + } + + /** + * Form changes for 'Publish to National Outreach Calendar' related elements. + * + * @param array $form + * The form array. + */ + public function modifyAddToOutreachCalendarElements(array &$form) :void { + if ($this->outreachHubOnlyUser() && $this->outreachCheckboxEnabled()) { + // Disable the checkbox. + $form[self::PUBLISH_TO_OUTREACH_CAL_FIELD]['#disabled'] = TRUE; + // Set the default value of the checkbox. + $form[self::PUBLISH_TO_OUTREACH_CAL_FIELD]['widget']['value']['#default_value'] = TRUE; + // Override the field label for the checkbox. + $form[self::PUBLISH_TO_OUTREACH_CAL_FIELD]['widget']['value']['#title'] = $this->t('This event will automatically be published to the National Outreach Calendar'); + // Set the default value to the Outreach cal on the dropdown if is not + // already set. + if (empty($form[self::LISTING_FIELD]['widget']['#default_value'])) { + $form[self::LISTING_FIELD]['widget']['#default_value'] = self::OUTREACH_CAL_NID; + } + } + // Add the '- Select a value -' option (_none) since it was removed by + // the Limited Widgets for Unlimited Field module. + if (isset($form[self::LISTING_FIELD]['widget']['#options']) && !array_key_exists('_none', $form[self::LISTING_FIELD]['widget']['#options'])) { + $form[self::LISTING_FIELD]['widget']['#options'] = ['_none' => '- Select a value -'] + $form[self::LISTING_FIELD]['widget']['#options']; + } + // Only allow access to the checkbox if it should be enabled. + $form[self::PUBLISH_TO_OUTREACH_CAL_FIELD]['#access'] = $this->outreachCheckboxEnabled(); } /** @@ -53,7 +248,7 @@ public function alterEventNodeForm(FormIdAlterEvent $event): void { * @param array $form * The form. */ - public function modifyRecurringEventsWidgetFieldPresentation(array &$form) { + public function modifyRecurringEventsWidgetFieldPresentation(array &$form): void { // Add our js for toggling items depending on duration choices. $form['#attached']['library'][] = 'va_gov_events/recurring_dates'; @@ -126,7 +321,7 @@ public function modifyRecurringEventsWidgetFieldPresentation(array &$form) { * @param array $form * The form. */ - public function addDisplayManagementToEventFields(array &$form) { + public function addDisplayManagementToEventFields(array &$form): void { $form['#attached']['library'][] = 'va_gov_events/event_form_states_helpers'; } @@ -140,7 +335,7 @@ public function addDisplayManagementToEventFields(array &$form) { * @param array $form * The form. */ - public function modifyFormFieldSetElements(array &$form) { + public function modifyFormFieldSetElements(array &$form): void { // Remove the wrap and title around address widget. $form['field_address']['widget'][0]['#type'] = 'div'; unset($form['field_address']['widget'][0]['#title']); diff --git a/docroot/modules/custom/va_gov_events/va_gov_events.services.yml b/docroot/modules/custom/va_gov_events/va_gov_events.services.yml index df7b43518a..57e983a823 100644 --- a/docroot/modules/custom/va_gov_events/va_gov_events.services.yml +++ b/docroot/modules/custom/va_gov_events/va_gov_events.services.yml @@ -1,7 +1,7 @@ services: va_gov_events.entity_event_subscriber: class: Drupal\va_gov_events\EventSubscriber\EntityEventSubscriber - arguments: ['@string_translation'] + arguments: ['@va_gov_user.user_perms', '@current_user', '@feature_toggle.feature_status'] tags: - { name: event_subscriber } va_gov_events.route_subscriber: diff --git a/docroot/themes/custom/vagovclaro/assets/scss/components/_fields.scss b/docroot/themes/custom/vagovclaro/assets/scss/components/_fields.scss index d3ee628d2f..7bfefb1ef9 100644 --- a/docroot/themes/custom/vagovclaro/assets/scss/components/_fields.scss +++ b/docroot/themes/custom/vagovclaro/assets/scss/components/_fields.scss @@ -226,3 +226,11 @@ body:not(.role-admin) { .magichead .fieldset__wrapper { margin-left: var(--spacing-xl); } + +#edit-field-publish-to-outreach-cal-wrapper div.form-item--field-publish-to-outreach-cal-value { + margin-left: auto; +} + +#edit-field-publish-to-outreach-cal-wrapper label { + margin-left: var(--spacing-xs); +} diff --git a/tests/cypress/integration/features/content_type/event.feature b/tests/cypress/integration/features/content_type/event.feature index 6920dce76b..58beddb9ef 100644 --- a/tests/cypress/integration/features/content_type/event.feature +++ b/tests/cypress/integration/features/content_type/event.feature @@ -2,15 +2,16 @@ Feature: Content Type: Event Scenario: Log in and create an event. - Given I am logged in as a user with the "content_admin" role + Given I am logged in as a user with the "administrator" role + When I set the "feature_event_outreach_checkbox" feature toggle to "on" Then I create a "event" node Scenario: Confirm that event form conditional fields are cleared out if parent options change Given I am logged in as a user with the "content_admin" role - And I am at "node/add/event" + When I am at "node/add/event" # Check registration call to action conditional field - When I select option "Register" from dropdown "Call to action" + And I select option "Register" from dropdown "Call to action" And I fill in autocomplete field with selector "#edit-field-url-of-an-online-event-0-uri" with value "/node/5016" And I select option "- None -" from dropdown "Call to action" And I select option "Register" from dropdown "Call to action" @@ -33,7 +34,6 @@ Feature: Content Type: Event And the option "- None -" from dropdown "State" should be selected When I select the "Online" radio button Then an element with the selector "#edit-field-url-of-an-online-event-0-uri" should be empty - # EVENT FORM SPECS Scenario: Confirm that the default time zone when creating an event is set explicitly to Eastern. Given I am logged in as a user with the "content_admin" role @@ -42,7 +42,7 @@ Feature: Content Type: Event Scenario: Confirm that the event form conditional elements are shown or hidden appropriately Given I am logged in as a user with the "content_admin" role - And I am at "node/add/event" + When I am at "node/add/event" And I select the "At a VA facility" radio button Then I should see "Facility location" @@ -71,7 +71,7 @@ Feature: Content Type: Event And I should not see "Country" And I should see an element with the selector "#edit-field-url-of-an-online-event-0-uri" - # Registration checkbox reveals conditional form elements +# Registration checkbox reveals conditional form elements When I check the "Include registration information" checkbox Then "Cost" should be visible And I should see "Registration is required for this event" diff --git a/tests/cypress/integration/features/platform/file_upload.feature b/tests/cypress/integration/features/platform/file_upload.feature deleted file mode 100644 index e3e3cc71a6..0000000000 --- a/tests/cypress/integration/features/platform/file_upload.feature +++ /dev/null @@ -1,11 +0,0 @@ -@file_upload -Feature: Files can be uploaded and attached to nodes successfully - In order to reliably and predictably create content - As anybody involved in the project - I need to be able to upload and attach files to nodes. - - Scenario: We should be able to attach files to event nodes. - Given I am logged in as a user with the "content_admin" role - When I create a "event" node - Then "polygon_image.png" should exist - And an image with the selector 'div.field--name-image a img' should exist diff --git a/tests/cypress/integration/step_definitions/common/i_create_a_node.js b/tests/cypress/integration/step_definitions/common/i_create_a_node.js index d3535e4114..ff6578e57a 100644 --- a/tests/cypress/integration/step_definitions/common/i_create_a_node.js +++ b/tests/cypress/integration/step_definitions/common/i_create_a_node.js @@ -244,6 +244,7 @@ const creators = { "VA Alaska health care: Events", { force: true } ); + cy.get("#edit-field-publish-to-outreach-cal-value").check(); cy.findAllByLabelText("Street address").type( faker.address.streetAddress(), { force: true } @@ -279,6 +280,7 @@ const creators = { ).should("exist"); cy.get("form.node-form").find("input#edit-submit").click(); cy.get(".node__content").contains("Sun, Nov 5 2023, 10:00am - 11:00am MST"); + cy.get(".node__content").contains("Outreach events"); cy.scrollTo("top", { ensureScrollable: false }); cy.get(".tabs__tab a").contains("Edit").click({ force: true }); cy.get("#edit-field-datetime-range-timezone-0-manage-instances").click(); diff --git a/tests/cypress/integration/step_definitions/common/i_set_a_feature_toggle.js b/tests/cypress/integration/step_definitions/common/i_set_a_feature_toggle.js new file mode 100644 index 0000000000..c85b95fbd2 --- /dev/null +++ b/tests/cypress/integration/step_definitions/common/i_set_a_feature_toggle.js @@ -0,0 +1,14 @@ +import { When } from "@badeball/cypress-cucumber-preprocessor"; + +When( + "I set the {string} feature toggle to {string}", + (featureToggleMachineName, value) => { + const label = String.prototype.toUpperCase(featureToggleMachineName); + // Set the feature toggle to the value of "value". + let setValue = 0; + if (value === "on") { + setValue = 1; + } + return cy.setAFeatureToggle(featureToggleMachineName, label, setValue); + } +); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 742ac2dbac..e16f61c225 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -321,6 +321,14 @@ Cypress.Commands.add("setWorkbenchAccessSections", (value) => { }); }); +Cypress.Commands.add("setAFeatureToggle", (name, label, value) => { + const command = ` + $feature = new \\Drupal\\feature_toggle\\Feature('${name}', '${label}'); + $service = \\Drupal::service('feature_toggle.feature_status')->setStatus($feature, ${value}); + `; + return cy.drupalDrushEval(command); +}); + compareSnapshotCommand(); Cypress.on("uncaught:exception", () => {