Skip to content

Commit

Permalink
refactor: implement switch statements to handle conditional form id l…
Browse files Browse the repository at this point in the history
…ogic for updated preprocess hooks
  • Loading branch information
nathanielwoodland committed Nov 27, 2023
1 parent db0d55c commit bd488ff
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions web/themes/custom/nysenate_theme/nysenate_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
}
}

Expand All @@ -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';
}
}
}
}

Expand Down

0 comments on commit bd488ff

Please sign in to comment.