From 7809b535cdfaee47eaeefa09ea8195f9a39af3cd Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 5 Apr 2024 17:26:00 +0300 Subject: [PATCH] Remove dependency to helfi_tpr_config from hdbt_admin_tools In some tests, hdbt_admin_tools and helfi_tpr are installed without helfi_tpr_config. This seems to cause crashes in Drupal\Core\Form\FormHelper::processStates(). --- .../hdbt_admin_tools/hdbt_admin_tools.module | 18 ------------------ .../helfi_tpr_config/helfi_tpr_config.module | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index 1a6cae69d..216ae33b2 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -147,24 +147,6 @@ function hdbt_admin_tools_form_node_form_alter(&$form, &$form_state, $form_id): $form['actions']['submit']['#submit'][] = 'hdbt_admin_tools_node_form_submit_callback'; } -/** - * Implements hook_form_FORM_ID_alter(). - */ -function hdbt_admin_tools_form_tpr_unit_form_alter(&$form, &$form_state, $form_id): void { - $form['field_phone_label']['#states'] = [ - 'visible' => [ - ':input[name="field_phone_with_contacts[value]"]' => ['checked' => TRUE], - ], - ]; - - // Required state must the widget rather than the form element. - $form['field_phone_label']['widget'][0]['value']['#states'] = [ - 'required' => [ - ':input[name="field_phone_with_contacts[value]"]' => ['checked' => TRUE], - ], - ]; -} - /** * Form submit callback for node forms. * diff --git a/modules/helfi_tpr_config/helfi_tpr_config.module b/modules/helfi_tpr_config/helfi_tpr_config.module index 20e6c7d97..dce867418 100644 --- a/modules/helfi_tpr_config/helfi_tpr_config.module +++ b/modules/helfi_tpr_config/helfi_tpr_config.module @@ -442,6 +442,24 @@ function template_preprocess_tpr_service_lower_content(array &$variables) : void } } +/** + * Implements hook_form_FORM_ID_alter(). + */ +function helfi_tpr_config_form_tpr_unit_form_alter(&$form, &$form_state, $form_id): void { + $form['field_phone_label']['#states'] = [ + 'visible' => [ + ':input[name="field_phone_with_contacts[value]"]' => ['checked' => TRUE], + ], + ]; + + // Required state must the widget rather than the form element. + $form['field_phone_label']['widget'][0]['value']['#states'] = [ + 'required' => [ + ':input[name="field_phone_with_contacts[value]"]' => ['checked' => TRUE], + ], + ]; +} + /** * Implements hook_form_FORM_ID_alter(). */