You are here

function sendinblue_signup_subscribe_form in SendinBlue 7.2

Same name and namespace in other branches
  1. 7 sendinblue.module \sendinblue_signup_subscribe_form()

Returns a subscription form for sendinblue lists.

1 string reference to 'sendinblue_signup_subscribe_form'
sendinblue_forms in ./sendinblue.module
Implements hook_forms().

File

./sendinblue.module, line 303
The entry point of Sendinblue module.

Code

function sendinblue_signup_subscribe_form($form, &$form_state, $signup, $type) {
  $sendinblueMailin = new SendinblueMailin();
  $form['#attributes'] = array(
    'class' => array(
      'sendinblue-signup-subscribe-form',
    ),
  );
  $form['description'] = array(
    '#markup' => check_plain($signup->settings['description']),
  );
  $form['fields'] = array(
    '#prefix' => '<div id="sendinblue-newsletter-' . check_plain($signup->settings['subscription']['settings']['list']) . '-mergefields" class="sendinblue-newsletter-mergefields">',
    '#suffix' => '</div>',
    '#tree' => TRUE,
  );
  if (isset($signup->settings['fields']['mergefields'])) {
    $merge_fields = $signup->settings['fields']['mergefields'];
    $attributes = $sendinblueMailin
      ->getAttributes()
      ->getAttributes();
    if (is_array($merge_fields)) {
      foreach ($merge_fields as $key => $value) {
        if ($key === 'EMAIL') {
          $form['fields'][$key] = array(
            '#type' => 'textfield',
            '#title' => check_plain($value['label']),
            '#attributes' => array(
              'style' => 'width:100%;box-sizing:border-box;',
            ),
            '#required' => TRUE,
          );
        }
        else {
          if (isset($value['check'])) {
            foreach ($attributes as $attribute) {
              if ($attribute
                ->getName() === $key) {
                $type = $attribute
                  ->getType();
                if ($type === 'category') {
                  $enumerations = $attribute
                    ->getEnumeration();
                }
                break;
              }
            }
            if ($type !== 'category') {
              $form['fields'][$key] = array(
                '#type' => 'textfield',
                '#title' => check_plain($value['label']),
                '#attributes' => array(
                  'style' => 'width:100%;box-sizing:border-box;',
                ),
                '#required' => isset($value['required']),
              );
            }
            else {
              $options = array();
              foreach ($enumerations as $enumeration) {
                $options[$enumeration['value']] = $enumeration['label'];
              }
              $form['fields'][$key] = array(
                '#type' => 'select',
                '#title' => check_plain($value['label']),
                '#options' => $options,
                '#attributes' => array(
                  'style' => 'width:100%;box-sizing:border-box;',
                ),
                '#required' => isset($value['required']),
              );
            }
          }
        }
      }
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#weight' => 10,
    '#value' => check_plain($signup->settings['fields']['submit_button']),
  );
  return $form;
}