class UserMenuAvatarConfigurationForm in User Menu Avatar (User Image in Menu) 8
Same name and namespace in other branches
- 8.5 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm
- 8.2 src/form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm
- 8.3 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm
- 8.4 src/Form/UserMenuAvatarConfigurationForm.php \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm
Defines our form class.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\user_menu_avatar\Form\UserMenuAvatarConfigurationForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of UserMenuAvatarConfigurationForm
1 string reference to 'UserMenuAvatarConfigurationForm'
File
- src/
form/ UserMenuAvatarConfigurationForm.php, line 15
Namespace
Drupal\user_menu_avatar\FormView source
class UserMenuAvatarConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'user_menu_avatar_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'user_menu_avatar.user_menu_avatar_settings',
];
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('user_menu_avatar.user_menu_avatar_settings')
->set('avatar_shape', $values['avatar_shape']);
$this
->config('user_menu_avatar.user_menu_avatar_settings')
->set('avatar_size', $values['avatar_size']);
$this
->config('user_menu_avatar.user_menu_avatar_settings')
->set('avatar_custom_image_field', $values['avatar_custom_image_field']);
$this
->config('user_menu_avatar.user_menu_avatar_settings')
->set('avatar_show_picture_and_name', $values['avatar_show_picture_and_name'])
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
UserMenuAvatarConfigurationForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
UserMenuAvatarConfigurationForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
UserMenuAvatarConfigurationForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
UserMenuAvatarConfigurationForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |