Skip to content

Commit

Permalink
Only show the Soil texture field if the lab test type is "soil".
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Sep 23, 2024
1 parent 1e81dbb commit 22816cc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/log/lab_test/farm_lab_test.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;

/**
* Lab test type options helper.
Expand Down Expand Up @@ -40,3 +41,14 @@ function farm_lab_test_type_options() {
function farm_lab_test_type_field_allowed_values(FieldStorageDefinitionInterface $definition, ?ContentEntityInterface $entity = NULL, bool &$cacheable = TRUE) {
return farm_lab_test_type_options();
}

/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function farm_lab_test_form_log_form_alter(&$form, FormStateInterface $form_state, $form_id) {

// Only show the "Soil texture" field if the lab test type is "soil".
if (isset($form['lab_test_type']) && isset($form['soil_texture'])) {
$form['soil_texture']['#states']['visible'] = [':input[name="lab_test_type"]' => ['value' => 'soil']];
}
}

0 comments on commit 22816cc

Please sign in to comment.