class Settings in Courier 8
Same name in this branch
- 8 src/Form/Settings.php \Drupal\courier\Form\Settings
- 8 courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings
Same name and namespace in other branches
- 2.x src/Form/Settings.php \Drupal\courier\Form\Settings
Configure Courier 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\courier\Form\Settings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of Settings
2 string references to 'Settings'
File
- src/
Form/ Settings.php, line 15
Namespace
Drupal\courier\FormView source
class Settings extends ConfigFormBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The RNG event manager.
*
* @var \Drupal\rng\EventManagerInterface
*/
protected $eventManager;
/**
* The identity channel manager.
*
* @var \Drupal\courier\Service\IdentityChannelManagerInterface
*/
protected $identityChannelManager;
/**
* 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.
* @param \Drupal\courier\Service\IdentityChannelManagerInterface $identity_channel_manager
* The identity channel manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, IdentityChannelManagerInterface $identity_channel_manager) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
$this->identityChannelManager = $identity_channel_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'), $container
->get('plugin.manager.identity_channel'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'courier_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'courier.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('courier.settings');
$preferences = $config
->get('channel_preferences');
$header = [
'label' => $this
->t('Channel'),
'weight' => $this
->t('Weight'),
'enabled' => [
'data' => $this
->t('Enabled'),
'class' => [
'checkbox',
],
],
];
$form['identity_channel_preference'] = [
'#title' => $this
->t('Channel preference defaults'),
'#type' => 'vertical_tabs',
];
$form['identity_types']['#tree'] = TRUE;
$identity_types = $this->identityChannelManager
->getIdentityTypes();
foreach ($identity_types as $identity_type) {
$entity_definition = $this->entityTypeManager
->getDefinition($identity_type);
$t_args = [
'@identity_type' => $entity_definition
->getLabel(),
];
$form['identity_types'][$identity_type] = [
'#type' => 'details',
'#title' => $entity_definition
->getLabel(),
'#open' => TRUE,
'#group' => 'identity_channel_preference',
];
$form['identity_types'][$identity_type]['channels'] = [
'#prefix' => '<p>' . $this
->t("The following channels are attempted, in order, for @identity_types who have not set preferences for themselves.\nThe first successful message for a channel will be transmitted, all subsequent channels are ignored.", $t_args) . '</p>',
'#type' => 'table',
'#header' => $header,
'#empty' => $this
->t('No channels found for @identity_type.'),
'#attributes' => [
'id' => 'identity-types-' . $identity_type,
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'channel-weight',
],
],
];
// Ensure channels are ordered correctly and apply is enabled to value.
$channels = [];
$channels_all = $this->identityChannelManager
->getChannelsForIdentityType($identity_type);
// Add existing channels in, ensure channels still exist.
if (array_key_exists($identity_type, $preferences)) {
$channels = array_fill_keys(array_intersect($preferences[$identity_type], $channels_all), TRUE);
}
// Add in channels missing (disabled) from config.
$channels += array_fill_keys(array_diff($channels_all, $channels), FALSE);
foreach ($channels as $channel => $enabled) {
$entity_definition = $this->entityTypeManager
->getDefinition($channel);
$t_args['@channel'] = $channel;
$row = [];
$row['#attributes']['class'][] = 'draggable';
$row['label']['#markup'] = $entity_definition
->getLabel();
$row['weight'] = [
'#type' => 'weight',
'#title' => t('Weight for @channel', $t_args),
'#title_display' => 'invisible',
'#default_value' => NULL,
'#attributes' => [
'class' => [
'channel-weight',
],
],
];
$row['enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enabled'),
'#title_display' => 'invisible',
'#default_value' => $enabled,
'#wrapper_attributes' => [
'class' => [
'checkbox',
],
],
];
$form['identity_types'][$identity_type]['channels'][$channel] = $row;
}
}
$form['devel'] = [
'#type' => 'details',
'#open' => TRUE,
];
$form['devel']['skip_queue'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Skip queue'),
'#description' => $this
->t('Whether messages skip the load balancing queue and process in the same request. Only turn on this setting when debugging, do not use it on production sites.'),
'#default_value' => $config
->get('skip_queue'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('courier.settings');
$channel_preferences = [];
foreach ($form_state
->getValue('identity_types') as $identity_type => $settings) {
foreach ($settings['channels'] as $channel => $row) {
if (!empty($row['enabled'])) {
$channel_preferences[$identity_type][] = $channel;
}
}
}
$config
->set('skip_queue', $form_state
->getValue('skip_queue'))
->set('channel_preferences', $channel_preferences)
->save();
drupal_set_message(t('Settings saved.'));
}
}
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 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:: |
protected | property | The messenger. | 29 |
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. | |
Settings:: |
protected | property | The entity type manager. | |
Settings:: |
protected | property | The RNG event manager. | |
Settings:: |
protected | property | The identity channel manager. | |
Settings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
Settings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
Settings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
Settings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
Settings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
Settings:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. |