You are here

class MenuPerRoleAdminSettings in Menu Per Role 8

Menu Per Role administration form.

@package Drupal\menu_per_role\Form

Hierarchy

Expanded class hierarchy of MenuPerRoleAdminSettings

1 file declares its use of MenuPerRoleAdminSettings
menu_per_role.module in ./menu_per_role.module
1 string reference to 'MenuPerRoleAdminSettings'
menu_per_role.routing.yml in ./menu_per_role.routing.yml
menu_per_role.routing.yml

File

src/Form/MenuPerRoleAdminSettings.php, line 19

Namespace

Drupal\menu_per_role\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MenuPerRoleAdminSettings::$entityTypeManager protected property The entity type manager service.
MenuPerRoleAdminSettings::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
MenuPerRoleAdminSettings::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
MenuPerRoleAdminSettings::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
MenuPerRoleAdminSettings::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
MenuPerRoleAdminSettings::MODE_DISPLAY_BOTH constant Display both hide and show role checkbox lists.
MenuPerRoleAdminSettings::MODE_DISPLAY_ONLY_HIDE constant Display only the hide from checkbox list.
MenuPerRoleAdminSettings::MODE_DISPLAY_ONLY_SHOW constant Display only the show to checkbox list.
MenuPerRoleAdminSettings::MODE_DISPLAY_ON_CONTENT_ALWAYS constant Always display fields on links to content.
MenuPerRoleAdminSettings::MODE_DISPLAY_ON_CONTENT_NEVER constant Never display fields on links to content.
MenuPerRoleAdminSettings::MODE_DISPLAY_ON_CONTENT_NO_NODE_ACCESS constant Only display fields on menu items if there are no node_access providers.
MenuPerRoleAdminSettings::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
MenuPerRoleAdminSettings::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.