public function UserMenuAvatarConfigurationForm::buildForm in User Menu Avatar (User Image in Menu) 8.4
Same name and namespace in other branches
- 8.5 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
- 8 src/form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
- 8.2 src/form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm::buildForm()
- 8.3 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\FormCode
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>'),
'#weight' => -10,
];
$form['link_text_name_wrapper'] = [
'#type' => 'fieldset',
'#weight' => 1,
'#title' => 'Link Settings',
'#attributes' => [
'class' => [
'link-text-name-wrapper',
],
],
];
$form['link_text_name_wrapper']['link_text_name'] = [
'#type' => 'textfield',
'#title' => t('Set link text'),
'#required' => TRUE,
'#description' => t('Set the text of the menu link to be replaced. Case sensitive. "My account" link is default.'),
'#maxlength' => 140,
'#size' => 60,
'#default_value' => $config
->get('link_text_name') ?: 'My account',
];
$form['show_menu_avatar_wrapper'] = [
'#type' => 'fieldset',
'#weight' => 2,
'#title' => 'Image Settings',
'#attributes' => [
'class' => [
'show-menu-avatar',
],
],
];
$form['show_menu_avatar_wrapper']['show_menu_avatar'] = [
'#type' => 'radios',
'#title' => t('Show Avatar'),
'#required' => TRUE,
'#options' => $avatar_yes_no_options,
'#description' => t('Choose to show the avatar.'),
'#default_value' => $config
->get('show_menu_avatar') ?: 'yes',
];
$form['show_menu_avatar_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',
'#states' => [
'visible' => [
':input[name="show_menu_avatar"]' => [
'value' => 'yes',
],
],
],
];
$form['show_menu_avatar_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',
'#states' => [
'visible' => [
':input[name="show_menu_avatar"]' => [
'value' => 'yes',
],
],
],
];
$form['show_menu_avatar_wrapper']['avatar_image_field'] = [
'#type' => 'textfield',
'#title' => t('Image field name'),
'#required' => TRUE,
'#description' => t('Will default to "user_picture" unless another field name is entered.'),
'#maxlength' => 140,
'#size' => 60,
'#default_value' => $config
->get('avatar_image_field') ?: 'user_picture',
'#states' => [
'visible' => [
':input[name="show_menu_avatar"]' => [
'value' => 'yes',
],
],
],
];
$form['show_menu_name_wrapper'] = [
'#type' => 'fieldset',
'#weight' => 4,
'#title' => 'Name Settings',
'#attributes' => [
'class' => [
'show-name-avatar',
],
],
];
$form['show_menu_name_wrapper']['show_menu_name'] = [
'#type' => 'radios',
'#title' => t('Show Name'),
'#required' => TRUE,
'#options' => $avatar_yes_no_options,
'#description' => t('Choose to show the user name. Defaults to "username" value.'),
'#default_value' => $config
->get('show_menu_name') ?: 'yes',
];
$form['show_menu_name_wrapper']['avatar_custom_name_field'] = [
'#type' => 'textfield',
'#title' => t('Custom name field name'),
'#required' => FALSE,
'#description' => t('Use a custom field for the user menu name. Leave blank to use default "username" value.'),
'#maxlength' => 140,
'#size' => 60,
'#default_value' => $config
->get('avatar_custom_name_field') ?: '',
'#states' => [
'visible' => [
':input[name="show_menu_name"]' => [
'value' => 'yes',
],
],
],
];
$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);
}