From 3ce3c5c836715dd4d18e8d8c575b15e4266b764d Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Thu, 4 Apr 2024 08:42:54 +0300 Subject: [PATCH] UHF-9496: Add form states --- .../hdbt_admin_tools/hdbt_admin_tools.module | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index 216ae33b2..1a6cae69d 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -147,6 +147,24 @@ 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. *