You are here

function simplify_hide_field in Simplify 8

Same name and namespace in other branches
  1. 7.3 simplify.module \simplify_hide_field()

Hide a given field in a form.

Parameters

string $field: The key for the field to simplify within a given form.

array $form: The form in which to simplify the given fields.

1 call to simplify_hide_field()
simplify_hide_fields in ./simplify.module
Hide fields from all users without the 'View hidden fields' permission.

File

./simplify.module, line 546
Hooks implemented by the simplify module.

Code

function simplify_hide_field(string $field, array &$form) {
  switch ($field) {

    // Entity translation.
    case 'entity_translation':
      $form['translation']['#attributes']['class'][] = 'visually-hidden';
      break;

    // Domain Access.
    case 'domain':
      $form['domain']['#attributes']['class'][] = 'visually-hidden';
      $form['field_domain_access']['#attributes']['class'][] = 'visually-hidden';
      $form['field_domain_admin']['#attributes']['class'][] = 'visually-hidden';
      $form['field_domain_all_affiliates']['#attributes']['class'][] = 'visually-hidden';
      break;

    // Text format selection.
    case 'format':
      simplify_hide_text_format_elements($form);
      break;

    // Status.
    case 'status':
      $form['account']['status']['#attributes']['class'][] = 'visually-hidden';
      break;
    default:
      $form[$field]['#attributes']['class'][] = 'visually-hidden';
  }

  // Allow other modules to alter the way fields are hidden.
  \Drupal::moduleHandler()
    ->alter('simplify_hide_field', $form, $field);
}