Skip to content

Commit

Permalink
fix: unable to save Page title display style field (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao authored Feb 26, 2025
1 parent 772e409 commit d5510d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
36 changes: 29 additions & 7 deletions modules/tide_landing_page/tide_landing_page.module
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function tide_landing_page_form_node_form_alter(&$form, FormStateInterface $form
}
}
}
$form['#validate'][] = 'tide_landing_page_header_style_node_form_validate';
}

// Add conditional field for show table of content.
Expand All @@ -170,6 +171,34 @@ function tide_landing_page_form_node_form_alter(&$form, FormStateInterface $form
}
}

/**
* Node form validate callback for Header style.
*/
function tide_landing_page_header_style_node_form_validate(array &$form, FormStateInterface $form_state) {
$header_style = $form_state->getValue('_header_style_options');
$hero_theme_value = $form_state->getValue(['field_landing_page_hero_theme', 0, 'value']);
$valid = TRUE;
$message = '';
switch ($header_style) {
case 'fullwidth':
if ($hero_theme_value !== 'dark') {
$valid = FALSE;
$message = t('When "Header style" is "Full-width background image", the "Page title display style" must be "Reverse blocked text".');
}
break;

case 'cta':
if ($hero_theme_value !== 'light') {
$valid = FALSE;
$message = t('When "Header style" is "Call to action banner", the "Page title display style" must be "Default".');
}
break;
}
if (!$valid) {
$form_state->setErrorByName('field_landing_page_hero_theme', $message);
}
}

/**
* Implements hook_field_widget_single_element_WIDGET_TYPE_form_alter().
*/
Expand Down Expand Up @@ -435,13 +464,6 @@ function _tide_landing_page_form_node_form_process(array $form, FormStateInterfa
],
];

$form['field_landing_page_hero_theme']['#states']['disabled'] = [
':input[name="_header_style_options"]' => [
['value' => 'fullwidth'],
['value' => 'cta'],
],
];

$form['field_landing_page_hero_image']['#states']['visible'] = [
':input[name="_header_style_options"]' => [
['value' => 'fullwidth'],
Expand Down
5 changes: 1 addition & 4 deletions modules/tide_publication/tide_publication.module
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function tide_publication_form_node_form_alter(&$form, FormStateInterface $form_
$form['field_node_display_headings']['widget']['#default_value'] = 'showH2';
}
}
$form['#validate'][] = 'tide_landing_page_header_style_node_form_validate';
}
}

Expand Down Expand Up @@ -125,10 +126,6 @@ function _tide_publication_form_node_form_process(array $form, FormStateInterfac
],
];

$form['field_landing_page_hero_theme']['#states']['enabled'] = [
':input[name="_header_style_options"]' => ['value' => 'corner'],
];

$form['field_landing_page_hero_image']['#states']['visible'] = [
':input[name="_header_style_options"]' => [
['value' => 'fullwidth'],
Expand Down

0 comments on commit d5510d1

Please sign in to comment.