You are here

function social_event_field_visibility in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/social_event.module \social_event_field_visibility()
  2. 10.0.x modules/social_features/social_event/social_event.module \social_event_field_visibility()
  3. 10.1.x modules/social_features/social_event/social_event.module \social_event_field_visibility()
  4. 10.2.x modules/social_features/social_event/social_event.module \social_event_field_visibility()

Add conditional field visibility triggers.

Parameters

array $form: The form that needs to be altered.

string $field_name: The field that acts as a trigger.

array $fields: The field that should show upon trigger.

string $state: Which state do you want for the form field. Defaults to visibility.

1 call to social_event_field_visibility()
social_event_form_alter in modules/social_features/social_event/social_event.module
Implements hook_form_alter().

File

modules/social_features/social_event/social_event.module, line 860
The Social event module.

Code

function social_event_field_visibility(array &$form, $field_name, array $fields, $state = 'visible') {

  // Todo: Refactor outside of an alter when going to React.
  // Hide fields if event enrollment is disabled for event.
  $trigger = [
    ':input[name="' . $field_name . '[value]"]' => [
      'checked' => TRUE,
    ],
  ];
  foreach ($fields as $field) {
    $form[$field]['#states'] = [
      $state => $trigger,
    ];
  }
}