class PopupAdminForm in Popup 8
Class PopupAdminForm.
@package Drupal\popup\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\popup\Form\PopupAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of PopupAdminForm
File
- src/
Form/ PopupAdminForm.php, line 22 - Contains \Drupal\popup\src\Form\PopupAdminForm.
Namespace
Drupal\popup\FormView 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
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 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:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PopupAdminForm:: |
protected | property |
The config factory. Overrides FormBase:: |
|
PopupAdminForm:: |
protected | property | Drupal\Core\Session\AccountProxyInterface definition. | |
PopupAdminForm:: |
protected | property |
Drupal\Core\Messenger\MessengerInterface definition. Overrides MessengerTrait:: |
|
PopupAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
PopupAdminForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
PopupAdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
PopupAdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PopupAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
PopupAdminForm:: |
public | function |
Class constructor. Overrides ConfigFormBase:: |
|
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. |