You are here

public function SettingsForm::buildForm in Forward 8

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::buildForm()
  2. 8.2 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::buildForm()
  3. 4.x src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::buildForm()
  4. 4.0.x src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::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

src/Form/SettingsForm.php, line 89

Class

SettingsForm
Configure settings for this module.

Namespace

Drupal\forward\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $forward_config = $this
    ->config('forward.settings');
  $settings = $forward_config
    ->get();

  // Entity Types
  $form['forward_entities'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Entity Types'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $options = array();
  $defaults = array();
  foreach ($entity_types as $type => $info) {
    if (is_a($info, 'Drupal\\Core\\Entity\\ContentEntityType')) {

      // Filter some entity types out
      if (!in_array($type, array(
        'block_content',
        'contact_message',
        'file',
        'menu_link_content',
        'node',
        'shortcut',
      ))) {
        $options[$type] = $info
          ->getLabel();
        if (!empty($settings['forward_entity_' . $type])) {
          $defaults[] = $type;
        }
      }
    }
  }
  $form['forward_entities']['forward_entity_types'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Entity types'),
    '#options' => $options,
    '#default_value' => $defaults,
    '#description' => t('Choose entity types to show Forward on.'),
  );

  // Bundles
  foreach ($entity_types as $type => $info) {
    if (is_a($info, 'Drupal\\Core\\Entity\\ContentEntityType')) {
      if (!empty($settings['forward_entity_' . $type]) || $type == 'node') {
        $bundles = $this->bundleInfoManager
          ->getBundleInfo($type);
        if (count($bundles) == 1) {
          foreach ($bundles as $bundle => $bundle_info) {
            $form['forward_entities']['forward_' . $type . '_types'] = array(
              '#type' => 'hidden',
              '#value' => $bundle,
            );
          }
        }
        else {
          $options = array();
          $defaults = array();
          foreach ($bundles as $bundle => $bundle_info) {
            $options[$bundle] = $bundle_info['label'];
            if (!empty($settings['forward_' . $type . '_' . $bundle])) {
              $defaults[] = $bundle;
            }
          }
          $form['forward_entities']['forward_' . $type . '_types'] = array(
            '#type' => 'checkboxes',
            '#title' => $this
              ->t($info
              ->getLabel() . ' bundles'),
            '#options' => $options,
            '#default_value' => $defaults,
            '#description' => $this
              ->t('Choose @type bundles to show Forward on.', array(
              '@type' => $info
                ->getLowercaseLabel(),
            )),
          );
        }
      }
    }
  }

  // View Modes
  $modes = array(
    'full' => t('Full entity'),
    'teaser' => t('Teaser'),
  );
  $options = array();
  $defaults = array();
  foreach ($modes as $mode => $info) {
    $options[$mode] = $info;
    if ($settings['forward_view_' . $mode]) {
      $defaults[] = $mode;
    }
  }
  $form['forward_entities']['forward_view_modes'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('View modes'),
    '#options' => $options,
    '#default_value' => $defaults,
    '#description' => $this
      ->t('Choose view modes to show Forward on.'),
  );

  // Interface
  $form['forward_interface'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Interface'),
    '#open' => FALSE,
  );
  $form['forward_interface']['forward_interface_type'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Interface type'),
    '#default_value' => $settings['forward_interface_type'],
    '#options' => array(
      'link' => t('Link to separate page'),
      'form' => t('Display inline form'),
    ),
    '#description' => $this
      ->t('Choose how the Forward form is reached from the displayed entity. Inline forms are displayed within a collapsible fieldset on the entity being forwarded.'),
  );
  $form['forward_interface']['forward_interface_title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title of interface element'),
    '#default_value' => $settings['forward_interface_title'],
    '#description' => $this
      ->t('Set the text of the link or fieldset title. Replacement tokens may be used.'),
    '#required' => TRUE,
  );
  $form['forward_interface']['forward_interface_weight'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Weight'),
    '#default_value' => $settings['forward_interface_weight'],
    '#description' => $this
      ->t('Set the weight of the link or inline form for positioning.'),
    '#required' => TRUE,
  );
  $form['forward_interface']['forward_link_options'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Link Options'),
    '#states' => array(
      'visible' => array(
        ':input[name=forward_interface_type]' => array(
          'value' => 'link',
        ),
      ),
    ),
  );
  $form['forward_interface']['forward_link_options']['forward_link_inline'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Place the link inline with other node links'),
    '#default_value' => $settings['forward_link_inline'],
    '#description' => $this
      ->t('Place inline with links like "Read more" and "Add comment". If not placed inline, or the entity is not a node, the link is added to the content area.'),
  );
  $form['forward_interface']['forward_link_options']['forward_link_title'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Page title'),
    '#default_value' => $settings['forward_link_title'],
    '#maxlength' => 255,
    '#description' => $this
      ->t('Page title for the Forward form page.'),
    '#required' => TRUE,
  );
  $form['forward_interface']['forward_link_options']['forward_link_style'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Style'),
    '#default_value' => $settings['forward_link_style'],
    '#options' => array(
      0 => $this
        ->t('Text only'),
      1 => t('Icon only'),
      2 => t('Icon and text'),
    ),
    '#description' => $this
      ->t('Select the visual style of the link.'),
  );
  $form['forward_interface']['forward_link_options']['forward_link_icon'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to custom icon'),
    '#default_value' => $settings['forward_link_icon'],
    '#description' => $this
      ->t('The path to your custom link icon instead of the default icon. Example: sites/default/files/icon.png'),
  );
  $form['forward_interface']['forward_link_options']['forward_link_noindex'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Generate a noindex meta tag on the forward page') . ' (name="robots", content="noindex, nofollow")',
    '#default_value' => $settings['forward_link_noindex'],
  );
  $form['forward_interface']['forward_link_options']['forward_link_nofollow'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Generate a nofollow tag on the forward link (rel="nofollow")'),
    '#default_value' => $settings['forward_link_nofollow'],
  );

  // Forward Form
  $form['forward_form'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Forward Form'),
    '#open' => FALSE,
  );
  $form['forward_form']['forward_form_instructions'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Instructions'),
    '#default_value' => $settings['forward_form_instructions'],
    '#rows' => 5,
    '#description' => $this
      ->t('The instructions to display above the form.  Replacement tokens may be used.  This field may contain HTML.'),
  );
  $form['forward_form']['form_display_options'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Form Fields'),
  );
  $form['forward_form']['form_display_options']['forward_form_display_page'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display a link to the page being forwarded'),
    '#default_value' => $settings['forward_form_display_page'],
  );
  $form['forward_form']['form_display_options']['forward_form_display_subject'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display the email message subject'),
    '#default_value' => $settings['forward_form_display_subject'],
  );
  $form['forward_form']['form_display_options']['forward_form_display_body'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display the email introductory message text'),
    '#default_value' => $settings['forward_form_display_body'],
  );
  $form['forward_form']['personal_messages'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Personal Message Field'),
  );
  $form['forward_form']['personal_messages']['forward_personal_message'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Personal message'),
    '#options' => array(
      0 => 'Hidden',
      1 => 'Optional',
      2 => 'Required',
    ),
    '#default_value' => $settings['forward_personal_message'],
    '#description' => $this
      ->t('Choose whether the personal message field on the form will be hidden, optional or required.'),
  );
  $form['forward_form']['personal_messages']['forward_personal_message_filter'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow HTML in personal messages'),
    '#return_value' => 1,
    '#default_value' => $settings['forward_personal_message_filter'],
    '#description' => $this
      ->t('Filter XSS and all tags not allowed below from the personal message.  Otherwise any HTML in the message will be converted to plain text.'),
    '#states' => array(
      'invisible' => array(
        ':input[name=forward_personal_message]' => array(
          'value' => 0,
        ),
      ),
    ),
  );
  $form['forward_form']['personal_messages']['forward_personal_message_tags'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed HTML tags'),
    '#default_value' => $settings['forward_personal_message_tags'],
    '#description' => $this
      ->t('List of tags (separated by commas) that will be allowed if HTML is enabled above.  Defaults to: p,br,em,strong,cite,code,ul,ol,li,dl,dt,dd'),
    '#states' => array(
      'invisible' => array(
        ':input[name=forward_personal_message]' => array(
          'value' => 0,
        ),
      ),
    ),
  );
  $form['forward_form']['forward_form_confirmation'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Confirmation message'),
    '#default_value' => $settings['forward_form_confirmation'],
    '#rows' => 5,
    '#description' => $this
      ->t('The thank you message displayed after the user successfully submits the form.  Replacement tokens may be used.'),
  );

  // Defaults for Message to Recipient
  $form['forward_email_defaults'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Forward Email'),
    '#open' => FALSE,
  );
  $form['forward_email_defaults']['forward_email_logo'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to custom logo'),
    '#default_value' => $settings['forward_email_logo'],
    '#maxlength' => 256,
    '#description' => $this
      ->t('The path to the logo you would like to use instead of the site default logo. Example: sites/default/files/logo.png'),
    '#required' => FALSE,
  );
  $form['forward_email_defaults']['forward_email_from_address'] = array(
    '#type' => 'email',
    '#title' => $this
      ->t('From address'),
    '#default_value' => $settings['forward_email_from_address'],
    '#maxlength' => 254,
    '#required' => TRUE,
  );
  $form['forward_email_defaults']['forward_email_subject'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Subject line'),
    '#default_value' => $settings['forward_email_subject'],
    '#maxlength' => 256,
    '#description' => $this
      ->t('Email subject line. Replacement tokens may be used.'),
    '#required' => TRUE,
  );
  $form['forward_email_defaults']['forward_email_message'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Introductory message text'),
    '#default_value' => $settings['forward_email_message'],
    '#rows' => 5,
    '#description' => $this
      ->t('Introductory text that appears above the entity being forwarded. Replacement tokens may be used. The sender may be able to add their own personal message after this.  This field may contain HTML.'),
  );

  // Post processing filters
  $filter_options = array();
  $filter_options[''] = t('- None -');
  foreach (filter_formats($this
    ->currentUser()) as $key => $format) {
    $filter_options[$key] = $format
      ->label();
  }
  if (count($filter_options) > 1) {
    $form['forward_filter_options'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('Filter'),
      '#open' => FALSE,
    );
    $form['forward_filter_options']['forward_filter_format'] = array(
      '#type' => 'select',
      '#title' => t('Filter format'),
      '#default_value' => $settings['forward_filter_format'],
      '#options' => $filter_options,
      '#description' => $this
        ->t('Select a filter to apply to the email message body. A filter with <a href="http://drupal.org/project/pathologic">Pathologic</a> assigned to it will convert relative links to absolute links. &nbsp;<a href="http://drupal.org/project/modules">More filters</a>.'),
    );
  }

  // Access Control
  $form['forward_access_control'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Access Control'),
    '#open' => FALSE,
    '#description' => $this
      ->t('The email build process normally uses anonymous visitor permissions to render the entity being forwarded.  This is appropriate for most sites.  If you bypass anonymous access control, and the person doing the forward is logged in, the permissions of the logged in account are used instead.  Bypassing anonymous access control creates a potential security risk because privileged information could be sent to people who are not authorized to view it.'),
  );
  $form['forward_access_control']['forward_bypass_access_control'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Bypass anonymous access control'),
    '#default_value' => $settings['forward_bypass_access_control'],
    '#description' => $this
      ->t('<em>Warning: selecting this option has security implications.</em>'),
  );

  // Flood Control
  $form['forward_flood_control_options'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Flood Control'),
    '#open' => FALSE,
  );
  $form['forward_flood_control_options']['forward_flood_control_limit'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Flood control limit'),
    '#default_value' => $settings['forward_flood_control_limit'],
    '#options' => array(
      '1' => '1',
      '5' => '5',
      '10' => '10',
      '15' => '15',
      '20' => '20',
      '25' => '25',
      '30' => '30',
      '35' => '35',
      '40' => '40',
      '50' => '50',
    ),
    '#description' => $this
      ->t('How many times a user can use the form in a one hour period. This will help prevent the forward module from being used for spamming.'),
  );
  $form['forward_flood_control_options']['forward_flood_control_error'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Flood control error'),
    '#default_value' => $settings['forward_flood_control_error'],
    '#rows' => 5,
    '#description' => $this
      ->t('This text appears if a user exceeds the flood control limit.  The value of the flood control limit setting will appear in place of @number in the message presented to users.'),
  );
  return parent::buildForm($form, $form_state);
}