public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $config = $this->config('swiftmailer.transport');
     // Submitted form values should be nested.
     $form['#tree'] = TRUE;
     // Display a page description.
     $form['description'] = array('#markup' => '<p>' . t('This page allows you to configure settings which determines how e-mail messages are sent.') . '</p>');
     // Validate that the Swift Mailer library is available. Configuration options
     // should only be displayed if the library is available.
     if (swiftmailer_validate_library($config->get('path', SWIFTMAILER_VARIABLE_PATH_DEFAULT))) {
         $form['transport'] = array('#id' => 'transport', '#type' => 'details', '#title' => t('Transport types'), '#description' => t('Which transport type should Drupal use to send e-mails?'), '#open' => TRUE);
         // Display the currently configured transport type, or alternatively the
         // currently selected transport type if the user has chosen to configure
         // another transport type.
         $transport = $config->get('transport', SWIFTMAILER_TRANSPORT_NATIVE);
         $transport = $form_state->hasValue(['transport', 'type']) ? $form_state->getValue(['transport', 'type']) : $transport;
         $form['transport']['type'] = array('#type' => 'radios', '#options' => array(SWIFTMAILER_TRANSPORT_SMTP => t('SMTP'), SWIFTMAILER_TRANSPORT_SENDMAIL => t('Sendmail'), SWIFTMAILER_TRANSPORT_NATIVE => t('PHP'), SWIFTMAILER_TRANSPORT_SPOOL => t('Spool')), '#default_value' => $transport, '#ajax' => array('callback' => array($this, 'ajaxCallback'), 'wrapper' => 'transport_configuration', 'method' => 'replace', 'effect' => 'fade'), '#description' => t('Not sure which transport type to choose? The !documentation gives you a good overview of the various transport types.', array('!documentation' => \Drupal::l($this->t('Swift Mailer documentation'), Url::fromUri('http://swiftmailer.org/docs/sending.html#transport-types')))));
         /*
         $form['transport']['submit'] = array(
           '#type' => 'submit',
           '#id' => 'transport_configuration_submit',
           '#value' => t('Configure'),
           '#submit' => array('swiftmailer_admin_transport_form_update'),
           '#limit_validation_errors' => array(array('transport', 'type')),
         );
         */
         $form['transport']['configuration'] = array('#type' => 'item', '#id' => 'transport_configuration');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP] = array('#type' => 'item', '#access' => $form['transport']['type']['#default_value'] == SWIFTMAILER_TRANSPORT_SMTP);
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['title'] = array('#markup' => '<h3>' . t('SMTP transport options') . '</h3>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['description'] = array('#markup' => '<p>' . t('This transport type will send all e-mails using a SMTP
     server of your choice. You need to specify which SMTP server
     to use. Please refer to the !documentation for more details
     about this transport type.', array('!documentation' => \Drupal::l($this->t('Swift Mailer documentation'), Url::fromUri('http://swiftmailer.org/docs/sending.html#the-smtp-transport')))) . '</p>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['server'] = array('#type' => 'textfield', '#title' => t('SMTP server'), '#description' => t('The hostname or IP address at which the SMTP server can be reached.'), '#required' => TRUE, '#default_value' => $config->get('smtp_host'));
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['port'] = array('#type' => 'textfield', '#title' => t('Port'), '#description' => t('The port at which the SMTP server can be reached (defaults to 25)'), '#default_value' => $config->get('smtp_port'), '#size' => 10);
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['encryption'] = array('#type' => 'select', '#title' => t('Encryption'), '#options' => swiftmailer_get_encryption_options(), '#description' => t('The type of encryption which should be used (if any)'), '#default_value' => $config->get('smtp_encryption'));
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['username'] = array('#type' => 'textfield', '#title' => t('Username'), '#description' => t('A username required by the SMTP server (leave blank if not required)'), '#default_value' => $config->get('smtp_username'), '#attributes' => array('autocomplete' => 'off'));
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['password'] = array('#type' => 'password', '#title' => t('Password'), '#description' => t('A password required by the SMTP server (leave blank if not required)'), '#default_value' => $config->get('smtp_password'), '#attributes' => array('autocomplete' => 'off'));
         $current_password = $config->get('smtp_password');
         if (!empty($current_password)) {
             $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SMTP]['password']['#description'] = t('A password
     required by the SMTP server. <em>The currently set password is hidden for security reasons</em>.');
         }
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL] = array('#type' => 'item', '#access' => $form['transport']['type']['#default_value'] == SWIFTMAILER_TRANSPORT_SENDMAIL);
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['title'] = array('#markup' => '<h3>' . t('Sendmail transport options') . '</h3>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['description'] = array('#markup' => '<p>' . t('This transport type will send all e-mails using a locally
     installed MTA such as Sendmail. You need to specify which
     locally installed MTA to use by providing a path to the
     MTA. If you do not provide any path then Swift Mailer
     defaults to /usr/sbin/sendmail. You can read more about
     this transport type in the !documentation.', array('!documentation' => \Drupal::l($this->t('Swift Mailer documentation'), Url::fromUri('http://swiftmailer.org/docs/sending.html#the-sendmail-transport')))) . '</p>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['path'] = array('#type' => 'textfield', '#title' => t('MTA path'), '#description' => t('The absolute path to the locally installed MTA.'), '#default_value' => $config->get('sendmail_path'));
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SENDMAIL]['mode'] = array('#type' => 'radios', '#title' => t('Mode'), '#options' => array('bs' => 'bs', 't' => 't '), '#description' => t('Not sure which option to choose? Go with <em>bs</em>. You can read more about the above two modes in the !documentation.', array('!documentation' => \Drupal::l($this->t('Swift Mailer documentation'), Url::fromUri('http://swiftmailer.org/docs/sendmail-transport')))), '#default_value' => $config->get('sendmail_mode'));
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_NATIVE] = array('#type' => 'item', '#access' => $form['transport']['type']['#default_value'] == SWIFTMAILER_TRANSPORT_NATIVE);
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_NATIVE]['title'] = array('#markup' => '<h3>' . t('PHP transport options') . '</h3>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_NATIVE]['description'] = array('#markup' => '<p>' . t('This transport type will send all e-mails using the built-in
     mail functionality of PHP. This transport type can not be
     configured here. Please refer to the !documentation if you
     would like to read more about how the built-in mail functionality
     in PHP can be configured.', array('!documentation' => \Drupal::l($this->t('PHP documentation'), Url::fromUri('http://www.php.net/manual/en/mail.configuration.php')))) . '</p>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SPOOL] = array('#type' => 'item', '#access' => $form['transport']['type']['#default_value'] == SWIFTMAILER_TRANSPORT_SPOOL);
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SPOOL]['title'] = array('#markup' => '<h3>' . t('Spool transport options') . '</h3>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SPOOL]['description'] = array('#markup' => '<p>' . t('This transport does not attempt to send the email
   but instead saves the message to a spool file. Another process can then
   read from the spool and take care of sending the emails.') . '</p>');
         $form['transport']['configuration'][SWIFTMAILER_TRANSPORT_SPOOL]['directory'] = array('#type' => 'textfield', '#title' => t('Spool directory'), '#description' => t('The absolute path to the spool directory.'), '#default_value' => $config->get('spool_directory', sys_get_temp_dir() . '/swiftmailer-spool'));
     } else {
         $form['message'] = array('#markup' => t('<p>You need to configure the location of the Swift Mailer library. Please visit the !page
     and configure the library to enable the configuration options on this page.</p>', array('!page' => \Drupal::l($this->t('library configuration page'), 'admin/config/people/swiftmailer'))));
     }
     return $form;
 }
Example #2
-1
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     $config = $this->config('swiftmailer.message');
     $form['#tree'] = TRUE;
     $form['description'] = array('#markup' => '<p>' . t('This page allows you to configure settings which determines how e-mail messages are created.') . '</p>');
     if (swiftmailer_validate_library($config->get('path', SWIFTMAILER_VARIABLE_PATH_DEFAULT))) {
         $form['format'] = array('#type' => 'fieldset', '#title' => t('Message format'), '#description' => t('You can set the default message format which should be applied to e-mail
       messages.'));
         $form['format']['type'] = array('#type' => 'radios', '#options' => array(SWIFTMAILER_FORMAT_PLAIN => t('Plain Text'), SWIFTMAILER_FORMAT_HTML => t('HTML')), '#default_value' => $config->get('format', SWIFTMAILER_VARIABLE_FORMAT_DEFAULT));
         $form['format']['respect'] = array('#type' => 'checkbox', '#title' => t('Respect provided e-mail format.'), '#default_value' => $config->get('respect_format', SWIFTMAILER_VARIABLE_RESPECT_FORMAT_DEFAULT), '#description' => t('The header "Content-Type", if available, will be respected if you enable this setting.
       Settings such as e-mail format ("text/plain" or "text/html") and character set may be provided through this
       header. Unless your site somehow alters e-mails, enabling this setting will result in all e-mails to be sent
       as plain text as this is the content type Drupal by default will apply to all e-mails.'));
         $form['convert'] = array('#type' => 'fieldset', '#title' => t('Plain Text Version'), '#description' => t('An alternative plain text version can be generated based on the HTML version if no plain text version
       has been explicitly set. The plain text version will be used by e-mail clients not capable of displaying HTML content.'), '#states' => array('visible' => array('input[type=radio][name=format[type]]' => array('value' => SWIFTMAILER_FORMAT_HTML))));
         $form['convert']['mode'] = array('#type' => 'checkbox', '#title' => t('Generate alternative plain text version.'), '#default_value' => $config->get('convert_mode', SWIFTMAILER_VARIABLE_CONVERT_MODE_DEFAULT), '#description' => t('Please refer to !link for more details about how the alternative plain text version will be generated.', array('!link' => \Drupal::l('html2text', Url::fromUri('http://www.chuggnutt.com/html2text')))));
         $form['character_set'] = array('#type' => 'fieldset', '#title' => t('Character Set'), '#description' => '<p>' . t('E-mails need to carry details about the character set which the
       receiving client should use to understand the content of the e-mail.
       The default character set is UTF-8.') . '</p>');
         $form['character_set']['type'] = array('#type' => 'select', '#options' => swiftmailer_get_character_set_options(), '#default_value' => $config->get('character_set', SWIFTMAILER_VARIABLE_CHARACTER_SET_DEFAULT));
     } else {
         $form['message'] = array('#markup' => '<p>' . t('You need to configure the location of the Swift Mailer library. Please visit the !page
       and configure the library to enable the configuration options on this page.', array('!page' => _l(t('library configuration page'), 'admin/config/people/swiftmailer'))) . '</p>');
     }
     return $form;
 }