class DefaultForm in Notify 8
Same name and namespace in other branches
- 2.0.x src/Form/DefaultForm.php \Drupal\notify\Form\DefaultForm
- 1.0.x src/Form/DefaultForm.php \Drupal\notify\Form\DefaultForm
Defines a form that configures forms module settings.
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\notify\Form\DefaultForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of DefaultForm
1 string reference to 'DefaultForm'
File
- src/
Form/ DefaultForm.php, line 17
Namespace
Drupal\notify\FormView source
class DefaultForm extends ConfigFormBase {
/**
* Drupal\Core\Messenger\MessengerInterface definition.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Drupal\Core\Extension\ModuleHandler definition.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected $moduleHandler;
/**
* Class constructor.
*
* @param ConfigFactoryInterface $config_factory
* The config factory.
* @param MessengerInterface $messenger
* The core messenger service.
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
*/
public function __construct(ConfigFactoryInterface $config_factory, MessengerInterface $messenger, ModuleHandler $module_handler) {
parent::__construct($config_factory);
$this->messenger = $messenger;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('messenger'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'notify_default_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'notify.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('notify.settings');
$set = 'defaults';
$form['notify_defaults'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Notification default for new users'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => $this
->t('The default master switch for new users (check for enabled, uncheck for disabled).'),
];
$form['notify_defaults']['notify_reg_default'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Receive e-mail notifications'),
'#return_value' => 1,
'#default_value' => $config
->get('notify_reg_default'),
];
$form['notify_defs'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Initial settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => $this
->t('These are the initial settings that will apply to new users registering, and to users that are enrolled in notifications with batch subscription.'),
];
$form['notify_defs']['node'] = [
'#type' => 'radios',
'#title' => $this
->t('Notify new content'),
'#default_value' => $config
->get('notify_def_node'),
'#options' => [
$this
->t('Disabled'),
$this
->t('Enabled'),
],
'#description' => $this
->t('Include new posts in the notification mail.'),
];
$form['notify_defs']['comment'] = [
'#type' => 'radios',
'#access' => $this->moduleHandler
->moduleExists('comment'),
'#title' => $this
->t('Notify new comments'),
'#default_value' => $config
->get('notify_def_comment'),
'#options' => [
$this
->t('Disabled'),
$this
->t('Enabled'),
],
'#description' => $this
->t('Include new comments in the notification mail.'),
];
$form['notify_defs']['teasers'] = [
'#type' => 'radios',
'#title' => $this
->t('How much to include?'),
'#default_value' => $config
->get('notify_def_teasers'),
'#options' => [
$this
->t('Title only'),
$this
->t('Title + Teaser/Excerpt'),
$this
->t('Title + Body'),
$this
->t('Title + Body + Fields'),
],
'#description' => $this
->t('Select the amount of each item to include in the notification e-mail.'),
];
$set = 'ntype';
$form[$set] = [
'#type' => 'fieldset',
'#title' => $this
->t('Notification by node type'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => $this
->t('Having nothing checked defaults to sending notifications about all node types.'),
];
$nodetypes = [];
foreach (NodeType::loadMultiple() as $type => $object) {
$nodetypes[$type] = $object
->label();
}
if (NULL !== $config
->get('notify_nodetypes')) {
$def_nodetypes = $config
->get('notify_nodetypes');
}
else {
$def_nodetypes = [];
}
$form[$set]['notify_nodetypes'] = [
'#type' => 'checkboxes',
'#title' => 'Node types',
'#options' => $nodetypes,
'#default_value' => $def_nodetypes,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('notify.settings')
->set('notify_reg_default', $values['notify_reg_default'])
->set('notify_def_node', $values['node'])
->set('notify_def_comment', $values['comment'])
->set('notify_def_teasers', $values['teasers'])
->set('notify_nodetypes', $values['notify_nodetypes'])
->save();
$this->messenger
->addMessage($this
->t('Notify default settings saved.'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DefaultForm:: |
protected | property |
Drupal\Core\Messenger\MessengerInterface definition. Overrides MessengerTrait:: |
|
DefaultForm:: |
protected | property | Drupal\Core\Extension\ModuleHandler definition. | |
DefaultForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
DefaultForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
DefaultForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
DefaultForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DefaultForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
DefaultForm:: |
public | function |
Class constructor. Overrides ConfigFormBase:: |
|
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. | |
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. |