You are here

class PopupAdminForm in Popup 8

Class PopupAdminForm.

@package Drupal\popup\Form

Hierarchy

Expanded class hierarchy of PopupAdminForm

File

src/Form/PopupAdminForm.php, line 22
Contains \Drupal\popup\src\Form\PopupAdminForm.

Namespace

Drupal\popup\Form
View source
class PopupAdminForm extends ConfigFormBase {

  /**
   * Drupal\Core\Session\AccountProxyInterface definition.
   *
   * @var AccountProxyInterface $currentUser
   */
  protected $currentUser;

  /**
   * Drupal\Core\Messenger\MessengerInterface definition.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * Class constructor.
   *
   * @param ConfigFactoryInterface $config_factory
   *   The config factory.
   * @param AccountProxyInterface $current_user
   *   The current user.
   * @param MessengerInterface $messenger
   *   The core messenger service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AccountProxyInterface $current_user, MessengerInterface $messenger) {
    parent::__construct($config_factory);
    $this->configFactory = $config_factory;
    $this->currentUser = $current_user;
    $this->messenger = $messenger;
  }

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

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'popup_admin.settings',
    ];
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    // Get current user data.
    $uid = $this->currentUser
      ->id();
    $this->messenger
      ->addMessage('Title: ' . $form_state
      ->getValue('title') . ', User UID: ' . $uid);
    $form['search_by_page_number_of_items'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Number of items to index per cron run'),
      '#options' => [
        10 => '10',
        20 => '20',
        50 => '50',
        100 => '100',
        200 => '200',
        500 => '500',
      ],
      '#default_value' => $this->configFactory
        ->get('search_by_page_number_of_items'),
      '#description' => $this
        ->t('The maximum number of items indexed in each pass of a :reports by Search by Page.', [
        ':reports' => 'cron maintenance task',
      ]),
      '#weight' => 1,
    ];
    $form['search_by_page_env'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Default environment'),
      '#options' => [
        1 => $this
          ->t('One'),
        2 => $this
          ->t('Two'),
        3 => $this
          ->t('Three'),
      ],
      '#default_value' => $this->configFactory
        ->get('search_by_page_env'),
      '#description' => $this
        ->t('The default environment is used for the Search by Page tab when using the core Search page.'),
      '#weight' => 2,
    ];
    $form['search_by_page_tab'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Search tab name'),
      '#default_value' => $this->configFactory
        ->get('search_by_page_tab') ?? $this
        ->t('Pages'),
      '#description' => $this
        ->t('If using Search by Page with the core Search module, the name of the tab where Search by Page results are shown.'),
      '#weight' => 2,
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('search_by_page.settings')
      ->set('search_by_page_number_of_items', $form_state
      ->getValue('search_by_page_number_of_items'))
      ->set('search_by_page_env', $form_state
      ->getValue('search_by_page_env'))
      ->set('search_by_page_tab', $form_state
      ->getValue('search_by_page_tab'))
      ->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::$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.
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PopupAdminForm::$configFactory protected property The config factory. Overrides FormBase::$configFactory
PopupAdminForm::$currentUser protected property Drupal\Core\Session\AccountProxyInterface definition.
PopupAdminForm::$messenger protected property Drupal\Core\Messenger\MessengerInterface definition. Overrides MessengerTrait::$messenger
PopupAdminForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
PopupAdminForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
PopupAdminForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
PopupAdminForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
PopupAdminForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
PopupAdminForm::__construct public function Class constructor. Overrides ConfigFormBase::__construct
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.