public function Settings::buildForm in Courier 8
Same name in this branch
- 8 src/Form/Settings.php \Drupal\courier\Form\Settings::buildForm()
- 8 courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::buildForm()
Same name and namespace in other branches
- 2.x courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- courier_system/
src/ Form/ Settings.php, line 124
Class
- Settings
- Configure Courier System settings.
Namespace
Drupal\courier_system\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('courier_system.settings');
$override = $config
->get('override');
// Actions.
$form['actions'] = [
'#type' => 'details',
'#attributes' => [
'class' => [
'container-inline',
],
],
'#open' => TRUE,
];
$form['actions']['operation'] = [
'#title' => $this
->t('With selection'),
'#type' => 'select',
'#options' => [
'copy_email' => $this
->t('Copy Drupal email to Courier'),
'enable' => $this
->t('Override Drupal email (enable selected)'),
'disable' => $this
->t('Restore Drupal email (disable selected)'),
'delete' => $this
->t('Delete'),
],
'#empty_option' => $this
->t(' - Select - '),
'#button_type' => 'primary',
];
$form['actions']['apply'] = [
'#type' => 'submit',
'#value' => $this
->t('Apply'),
'#button_type' => 'primary',
];
// List items.
$form['list'] = [
'#type' => 'courier_template_collection_list',
'#title' => $this
->t('Replace Drupal mails'),
'#checkboxes' => TRUE,
'#items' => [],
];
$header = [
$this
->t('Module'),
$this
->t('Description'),
];
$form['add_missing'] = [
'#type' => 'details',
'#title' => $this
->t('Add missing messages'),
];
$form['add_missing']['table'] = [
'#type' => 'table',
'#header' => $header,
'#tree' => TRUE,
'#tableselect' => TRUE,
'#multiple' => TRUE,
'#empty' => $this
->t('No messages are missing.'),
];
$form['add_missing']['submit'] = [
'#type' => 'submit',
'#value' => t('Create messages'),
'#submit' => [
[
$this,
'submitCreateMessages',
],
],
];
foreach ($this
->getSystemMails() as $module => $mails) {
foreach ($mails as $mail_id => $definition) {
$gtc_id = 'courier_system.' . $mail_id;
if ($gtc = GlobalTemplateCollection::load($gtc_id)) {
$template_collection = $gtc
->getTemplateCollection();
$form['list']['#items'][$mail_id] = [
'#title' => $this
->t('@module: @title (@status)', [
'@title' => $definition['title'],
'@module' => \Drupal::moduleHandler()
->getName($module),
'@status' => !empty($override[$mail_id]) ? $this
->t('enabled - using Courier') : $this
->t('disabled - using Drupal'),
]),
'#description' => $definition['description'],
'#template_collection' => $template_collection,
];
}
else {
$row = [];
$row['module']['#markup'] = \Drupal::moduleHandler()
->getName($module);
$row['title']['#markup'] = $definition['title'];
$form['add_missing']['table'][$mail_id] = $row;
}
}
}
$form['add_missing']['#open'] = !count($form['list']['#items']);
if ($count = count(Element::children($form['add_missing']['table']))) {
$form['add_missing']['#title'] = $this
->t('Add missing messages (@count)', [
'@count' => $count,
]);
}
return $form;
}