class MenuPerRoleAdminSettings in Menu Per Role 8
Menu Per Role administration form.
@package Drupal\menu_per_role\Form
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\menu_per_role\Form\MenuPerRoleAdminSettings implements ContainerInjectionInterface
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of MenuPerRoleAdminSettings
1 file declares its use of MenuPerRoleAdminSettings
1 string reference to 'MenuPerRoleAdminSettings'
File
- src/
Form/ MenuPerRoleAdminSettings.php, line 19
Namespace
Drupal\menu_per_role\FormView source
class MenuPerRoleAdminSettings extends ConfigFormBase implements ContainerInjectionInterface {
/**
* Display both hide and show role checkbox lists.
*/
const MODE_DISPLAY_BOTH = 0;
/**
* Display only the hide from checkbox list.
*/
const MODE_DISPLAY_ONLY_HIDE = 1;
/**
* Display only the show to checkbox list.
*/
const MODE_DISPLAY_ONLY_SHOW = 2;
/**
* Always display fields on links to content.
*/
const MODE_DISPLAY_ON_CONTENT_ALWAYS = 0;
/**
* Only display fields on menu items if there are no node_access providers.
*/
const MODE_DISPLAY_ON_CONTENT_NO_NODE_ACCESS = 1;
/**
* Never display fields on links to content.
*/
const MODE_DISPLAY_ON_CONTENT_NEVER = 2;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) : self {
return new self($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'menu_per_role.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'menu_per_role_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('menu_per_role.settings');
$form['admin_bypass'] = [
'#type' => 'details',
'#title' => $this
->t('Administrator bypass'),
'#description' => $this
->t('The user with UID 1 and the users with the "admin" role configured on the <a href=":url">Account settings</a> page (or marked via config) have all the permissions. So they will automatically bypass Menu Per Role access check due to the bypass permissions. These settings allows you to configure if those users can bypass or not Menu Per Role access check.'),
'#open' => TRUE,
];
$form['admin_bypass']['admin_bypass_access_front'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Administrator role bypass access check in front'),
'#default_value' => $config
->get('admin_bypass_access_front'),
];
$form['admin_bypass']['admin_bypass_access_admin'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Administrator role bypass access check in admin context'),
'#default_value' => $config
->get('admin_bypass_access_admin'),
];
$form['hide_show'] = [
'#type' => 'radios',
'#title' => $this
->t('Select what is shown when editing menu items'),
'#options' => [
static::MODE_DISPLAY_BOTH => $this
->t('Hide and Show check boxes'),
static::MODE_DISPLAY_ONLY_HIDE => $this
->t('Only Hide check boxes'),
static::MODE_DISPLAY_ONLY_SHOW => $this
->t('Only Show check boxes'),
],
'#description' => $this
->t('By default, both list of check boxes are shown when editing a menu item (in the menu administration area or while editing a node.) This option let you choose to only show the "Show menu item only to selected roles" or "Hide menu item from selected roles". WARNING: changing this option does not change the existing selection. This means some selection will become invisible when you hide one of the set of check boxes...'),
'#default_value' => $config
->get('hide_show'),
];
$form['hide_on_content'] = [
'#type' => 'radios',
'#title' => $this
->t('Show fields on menu items that point to content'),
'#options' => [
static::MODE_DISPLAY_ON_CONTENT_ALWAYS => $this
->t('Always'),
static::MODE_DISPLAY_ON_CONTENT_NO_NODE_ACCESS => $this
->t('If NO Node Access Modules are enabled.'),
static::MODE_DISPLAY_ON_CONTENT_NEVER => $this
->t('Never'),
],
'#description' => $this
->t('Fields are shown when editing any menu item. This will hide the fields when editing menu items, that point to nodes. This is useful on sites using Node Access modules.'),
'#default_value' => $config
->get('hide_on_content'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) : void {
$this
->config('menu_per_role.settings')
->set('admin_bypass_access_front', $form_state
->getValue('admin_bypass_access_front'))
->set('admin_bypass_access_admin', $form_state
->getValue('admin_bypass_access_admin'))
->set('hide_show', $form_state
->getValue('hide_show'))
->set('hide_on_content', $form_state
->getValue('hide_on_content'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
MenuPerRoleAdminSettings:: |
protected | property | The entity type manager service. | |
MenuPerRoleAdminSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
MenuPerRoleAdminSettings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
MenuPerRoleAdminSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
MenuPerRoleAdminSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
MenuPerRoleAdminSettings:: |
constant | Display both hide and show role checkbox lists. | ||
MenuPerRoleAdminSettings:: |
constant | Display only the hide from checkbox list. | ||
MenuPerRoleAdminSettings:: |
constant | Display only the show to checkbox list. | ||
MenuPerRoleAdminSettings:: |
constant | Always display fields on links to content. | ||
MenuPerRoleAdminSettings:: |
constant | Never display fields on links to content. | ||
MenuPerRoleAdminSettings:: |
constant | Only display fields on menu items if there are no node_access providers. | ||
MenuPerRoleAdminSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
MenuPerRoleAdminSettings:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. |