From bd488ff548a7fc5223f7bfbcd3e70c084888efb1 Mon Sep 17 00:00:00 2001 From: Nathaniel Woodland Date: Mon, 27 Nov 2023 13:07:59 -0500 Subject: [PATCH] refactor: implement switch statements to handle conditional form id logic for updated preprocess hooks --- .../nysenate_theme/nysenate_theme.theme | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/web/themes/custom/nysenate_theme/nysenate_theme.theme b/web/themes/custom/nysenate_theme/nysenate_theme.theme index c934d626f8..a2f8d62620 100644 --- a/web/themes/custom/nysenate_theme/nysenate_theme.theme +++ b/web/themes/custom/nysenate_theme/nysenate_theme.theme @@ -5196,14 +5196,14 @@ function nysenate_theme_preprocess_views_view_table(&$variables) { * Implements hook_preprocess_datetime_wrapper(). */ function nysenate_theme_preprocess_datetime_wrapper(&$variables) { - if (!empty($variables['element']['#id'])) { + $id = $variables['element']['#id'] ?? ''; + switch ($id) { // Dashboard Profile Edit design fix. - if ($variables['element']['#id'] == 'edit-field-dateofbirth-0-value') { + case 'edit-field-dateofbirth-0-value': $current_path = \Drupal::request()->getRequestUri(); if (str_starts_with($current_path, '/dashboard/edit')) { unset($variables['title']); } - } } } @@ -5218,31 +5218,27 @@ function nysenate_theme_preprocess_form_element(&$variables) { } } - if (!empty($variables['element']['#id'])) { - if ($variables['element']['#id'] == 'edit-field-address-0-address-address-line2') { + $id = $variables['element']['#id'] ?? ''; + switch ($id) { + case 'edit-field-address-0-address-address-line2': $variables['label_display'] = 'before'; $variables['label']['#title'] = t('APT/SUITE/FLOOR (OPTIONAL)'); $variables['label']['#title_display'] = 'before'; - } - if ($variables['element']['#id'] == 'edit-field-address-0-address-address-line1--2') { + case 'edit-field-address-0-address-address-line1--2': $variables['label']['#title'] = t('STREET'); - } - if ($variables['element']['#id'] == 'edit-field-address-0-address-address-line2--2') { + case 'edit-field-address-0-address-address-line2--2': $variables['label_display'] = 'before'; $variables['label']['#title'] = t('ADDITIONAL'); $variables['label']['#title_display'] = 'before'; - } - if ($variables['element']['#id'] == 'edit-field-address-0-address-administrative-area--2') { + case 'edit-field-address-0-address-administrative-area--2': $variables['label']['#title'] = t('STATE/PROVINCE'); - } - if ($variables['element']['#id'] == 'edit-field-dateofbirth-0-value-date') { + case 'edit-field-dateofbirth-0-value-date': $current_path = \Drupal::request()->getRequestUri(); if (str_starts_with($current_path, '/dashboard/edit')) { $variables['label_display'] = 'before'; $variables['label']['#title'] = t('DATE OF BIRTH'); $variables['label']['#title_display'] = 'before'; } - } } }