You are here

class ModuleSettingsForm in Layout Builder Styles 8

Class ModuleSettingsForm.

Hierarchy

Expanded class hierarchy of ModuleSettingsForm

1 string reference to 'ModuleSettingsForm'
layout_builder_styles.routing.yml in ./layout_builder_styles.routing.yml
layout_builder_styles.routing.yml

File

src/Form/ModuleSettingsForm.php, line 13

Namespace

Drupal\layout_builder_styles\Form
View source
class ModuleSettingsForm extends FormBase {

  /**
   * Drupal\Core\Config\ConfigManager definition.
   *
   * @var \Drupal\Core\Config\ConfigManager
   */
  protected $configManager;

  /**
   * Constructs a new RestrictionPluginConfigForm object.
   */
  public function __construct(ConfigManager $config_manager) {
    $this->configManager = $config_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'layout_builder_styles_config_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->configFactory()
      ->get('layout_builder_styles.settings');
    $form['multiselect'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Multiple styles'),
      '#default_value' => $config
        ->get('multiselect'),
      '#options' => [
        'single' => $this
          ->t('Limit one style per given section or block.'),
        'multiple' => $this
          ->t('Allow multiple styles to be selected on a given section or block.'),
      ],
      '#description' => $this
        ->t('Limiting to one style per section or block is useful for sites which need each style choice to dictate the markup of the template. When this option is chosen, a corresponding block theme hook suggestion is provided. Allowing multiple styles is useful for sites whose style declarations correspond wholly to CSS modifications, and whose styles are designed to be used in conjunction. <strong>Note</strong>: if you switch this setting from "multiple" to "single" after Layout Builder Styles is already in use, any blocks that had been assigned multiple styles will initially continue to render with multiple styles until the block form is revisted; at that point, the Layout Builder Style options will be reset to no selections, and content editors should take care to reapply the single style they want to use.'),
    ];
    $form['form_type'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Form element for multiple styles'),
      '#default_value' => $config
        ->get('form_type'),
      '#options' => [
        'checkboxes' => $this
          ->t('Checkboxes'),
        'multiple-select' => $this
          ->t('Select (multiple) box'),
      ],
      '#description' => $this
        ->t('Choose whether the styles selector should display as multiple checkboxes or a select (multiple) box.'),
      '#states' => [
        'visible' => [
          ':input[name="multiselect"]' => [
            'value' => 'multiple',
          ],
        ],
      ],
    ];
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save configuration'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $multiselect = $form_state
      ->getValue('multiselect');
    $form_type = $form_state
      ->getValue('form_type');
    $config = $this
      ->configFactory()
      ->getEditable('layout_builder_styles.settings');
    $config
      ->set('multiselect', $multiselect);
    $config
      ->set('form_type', $form_type);
    $config
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::config protected function Retrieves a configuration object.
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.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
ModuleSettingsForm::$configManager protected property Drupal\Core\Config\ConfigManager definition.
ModuleSettingsForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
ModuleSettingsForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
ModuleSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ModuleSettingsForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
ModuleSettingsForm::__construct public function Constructs a new RestrictionPluginConfigForm object.
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.