class UserMenuAvatarConfigurationForm 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
- 8 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
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>'),
'#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);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this->configFactory
->getEditable('user_menu_avatar.user_menu_avatar_settings')
->set('avatar_shape', $values['avatar_shape'])
->set('link_text_name', $values['link_text_name'])
->set('avatar_size', $values['avatar_size'])
->set('avatar_image_field', $values['avatar_image_field'])
->set('show_menu_avatar', $values['show_menu_avatar'])
->set('show_menu_name', $values['show_menu_name'])
->set('avatar_custom_name_field', $values['avatar_custom_name_field'])
->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:: |