You are here

function gdpr_tasks_email_settings_subform in General Data Protection Regulation 7

Build the form elements for a particular email.

Parameters

string $key: The form key for the element.

string $title: The translated title for this email.

string $description: The translated description for this email.

array $settings: An array of settings for this email.

array $tokens: An optional array of tokens which are supported for this email.

Return value

array A fieldset form element array.

1 call to gdpr_tasks_email_settings_subform()
gdpr_tasks_email_settings in modules/gdpr_tasks/gdpr_tasks.admin.inc
Config form for automated emails for task requests.

File

modules/gdpr_tasks/gdpr_tasks.admin.inc, line 369
Administrative page and form callbacks for the GDPR Tasks module.

Code

function gdpr_tasks_email_settings_subform($key, $title, $description, array $settings = array(), array $tokens = array()) {

  // Pull the relevant key out of the settings.
  $settings = isset($settings[$key]) ? $settings[$key] : array();

  // Build our fieldset.
  $element = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#group' => 'gdpr_tasks_emails][emails',
    '#title' => $title,
    '#description' => $description,
  );

  // Allow this email to be enabled/disabled.
  $element['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable %title', array(
      '%title' => $title,
    )),
    '#default_value' => !empty($settings['enabled']),
    '#gdpr_tasks_email_dependents' => array(
      array(
        'email',
        'subject',
      ),
      array(
        'email',
        'body',
        'value',
      ),
    ),
  );
  $element['email'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        ":input[name=\"gdpr_tasks_emails[{$key}][enabled]\"]" => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#parents' => array(
      'gdpr_tasks_emails',
      $key,
    ),
  );

  // If we have tokens, output some help information.
  if (!empty($tokens)) {
    $element['email']['tokens'] = array(
      '#theme' => 'token_tree_link',
      '#token_types' => $tokens,
    );
  }

  // Subject line.
  $element['email']['subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#default_value' => isset($settings['subject']) ? $settings['subject'] : NULL,
    '#maxlength' => 180,
    '#states' => array(
      'required' => array(
        ":input[name=\"gdpr_tasks_emails[{$key}][enabled]\"]" => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Body with format.
  $element['email']['body'] = array(
    '#type' => 'text_format',
    '#title' => t('Body'),
    '#rows' => 15,
    '#format' => isset($settings['body']['format']) ? $settings['body']['format'] : NULL,
    '#default_value' => isset($settings['body']['value']) ? $settings['body']['value'] : NULL,
    '#states' => array(
      'required' => array(
        ":input[name=\"gdpr_tasks_emails[{$key}][enabled]\"]" => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Return with our key.
  return array(
    $key => $element,
  );
}