You are here

public function UserMenuAvatarConfigurationForm::buildForm in User Menu Avatar (User Image in Menu) 8

Same name and namespace in other branches
  1. 8.5 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
  2. 8.2 src/form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
  3. 8.3 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
  4. 8.4 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/form/UserMenuAvatarConfigurationForm.php, line 36

Class

UserMenuAvatarConfigurationForm
Defines our form class.

Namespace

Drupal\user_menu_avatar\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('user_menu_avatar.user_menu_avatar_settings');
  $avatar_shape_options = [
    'circle' => t('Circle'),
    'square' => t('Square'),
  ];
  $avatar_yes_no_options = [
    'yes' => t('Yes'),
    'no' => t('No'),
  ];
  $form['user_avatar_heading'] = [
    '#type' => 'item',
    '#markup' => t('<h2>Available User Menu Avatar Settings</h2>'),
  ];
  $form['avatar_shape_wrapper'] = [
    '#type' => 'fieldset',
    '#weight' => 0,
    '#attributes' => [
      'class' => [
        'avatar-shape',
      ],
    ],
  ];
  $form['avatar_shape_wrapper']['avatar_shape'] = [
    '#type' => 'radios',
    '#title' => t('User Menu Avatar Shape'),
    '#required' => TRUE,
    '#options' => $avatar_shape_options,
    '#description' => t('Choose the shape of the avatar image in the user menu.'),
    '#default_value' => $config
      ->get('avatar_shape') ?: 'circle',
  ];
  $form['avatar_size_wrapper'] = [
    '#type' => 'fieldset',
    '#weight' => 1,
    '#attributes' => [
      'class' => [
        'avatar-size',
      ],
    ],
  ];
  $form['avatar_size_wrapper']['avatar_size'] = [
    '#type' => 'textfield',
    '#attributes' => [
      ' type' => 'number',
    ],
    '#title' => t('User Menu Avatar Size (px)'),
    '#required' => TRUE,
    '#description' => t('The size of the User Menu Avatar in "pixels". Applies to both width and height. Numeric value only.'),
    '#maxlength' => 3,
    '#size' => 30,
    '#default_value' => $config
      ->get('avatar_size') ?: '50',
  ];
  $form['avatar_custom_image_field_wrapper'] = [
    '#type' => 'fieldset',
    '#weight' => 3,
    '#attributes' => [
      'class' => [
        'avatar-custom-image-field',
      ],
    ],
  ];
  $form['avatar_custom_image_field_wrapper']['avatar_custom_image_field'] = [
    '#type' => 'textfield',
    '#attributes' => [
      ' type' => 'text',
    ],
    '#title' => t('Custom Image Field Name (in place of, or to override, the user_picture field)'),
    '#required' => FALSE,
    '#description' => t('If you would like to use a custom field instead of the user_picture field, enter the field machine name here. *Field must be on the User Account'),
    '#maxlength' => 140,
    '#size' => 60,
    '#default_value' => $config
      ->get('avatar_custom_image_field' ?: ''),
  ];
  $form['avatar_show_picture_and_name_wrapper'] = [
    '#type' => 'fieldset',
    '#weight' => 4,
    '#attributes' => [
      'class' => [
        'avatar-show-picture-and-name',
      ],
    ],
  ];
  $form['avatar_show_picture_and_name_wrapper']['avatar_show_picture_and_name'] = [
    '#type' => 'radios',
    '#title' => t('Show Both Picture and Name'),
    '#required' => FALSE,
    '#options' => $avatar_yes_no_options,
    '#description' => t('Choose to show both the user_picture and the username.'),
    '#default_value' => $config
      ->get('avatar_show_picture_and_name') ?: 'no',
  ];
  $form['form_info'] = [
    '#type' => 'item',
    '#weight' => 10,
    '#markup' => t('<p>User Menu Avatar uses Background-image CSS to position the user_picture. The width and height are set by inline styles on the span element. The border radius only applies if you choose shape circle.</p>'),
  ];
  return parent::buildForm($form, $form_state);
}