/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['emails'] = array('#type' => 'textarea', '#title' => t('Email addresses'), '#cols' => 60, '#rows' => 5, '#description' => t('Email addresses must be separated by comma, space or newline.')); $form['newsletters'] = array('#type' => 'checkboxes', '#title' => t('Unsubscribe from'), '#options' => simplenews_newsletter_list(), '#required' => TRUE); foreach (simplenews_newsletter_get_all() as $id => $newsletter) { $form['newsletters'][$id]['#description'] = SafeMarkup::checkPlain($newsletter->description); } $form['submit'] = array('#type' => 'submit', '#value' => t('Unsubscribe')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Get sensible default values for the form elements in this form. $default['states'] = isset($_GET['states']) ? $_GET['states'] : array('active' => 'active'); $default['subscribed'] = isset($_GET['subscribed']) ? $_GET['subscribed'] : array('subscribed' => 'subscribed'); $default['newsletters'] = isset($_GET['newsletters']) ? $_GET['newsletters'] : array(); $form['states'] = array('#type' => 'checkboxes', '#title' => t('Status'), '#options' => array('active' => t('Active users'), 'inactive' => t('Inactive users')), '#default_value' => $default['states'], '#description' => t('Subscriptions matching the selected states will be exported.'), '#required' => TRUE); $form['subscribed'] = array('#type' => 'checkboxes', '#title' => t('Subscribed'), '#options' => array('subscribed' => t('Subscribed to the newsletter'), 'unconfirmed' => t('Unconfirmed to the newsletter'), 'unsubscribed' => t('Unsubscribed from the newsletter')), '#default_value' => $default['subscribed'], '#description' => t('Subscriptions matching the selected subscription states will be exported.'), '#required' => TRUE); $options = simplenews_newsletter_list(); $form['newsletters'] = array('#type' => 'checkboxes', '#title' => t('Newsletter'), '#options' => $options, '#default_value' => $default['newsletters'], '#description' => t('Subscriptions matching the selected newsletters will be exported.'), '#required' => TRUE); // Get export results and display them in a text area. Only get the results // if the form is build after redirect, not after submit. $input = $form_state->getUserInput(); if (isset($_GET['states']) && empty($input)) { $form['emails'] = array('#type' => 'textarea', '#title' => t('Export results'), '#cols' => 60, '#rows' => 5, '#value' => $this->getEmails($_GET['states'], $_GET['subscribed'], $_GET['newsletters'])); } $form['submit'] = array('#type' => 'submit', '#value' => t('Export')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['emails'] = array('#type' => 'textarea', '#title' => t('Email addresses'), '#cols' => 60, '#rows' => 5, '#description' => t('Email addresses must be separated by comma, space or newline.')); $form['newsletters'] = array('#type' => 'checkboxes', '#title' => t('Subscribe to'), '#options' => simplenews_newsletter_list(), '#required' => TRUE); foreach (simplenews_newsletter_get_all() as $id => $newsletter) { $form['newsletters'][$id]['#description'] = SafeMarkup::checkPlain($newsletter->description); } $form['resubscribe'] = array('#type' => 'checkbox', '#title' => t('Force resubscription'), '#description' => t('If checked, previously unsubscribed e-mail addresses will be resubscribed. Consider that this might be against the will of your users.')); // Include language selection when the site is multilingual. // Default value is the empty string which will result in receiving emails // in the site's default language. if (\Drupal::languageManager()->isMultilingual()) { $options[''] = t('Site default language'); $languages = \Drupal::languageManager()->getLanguages(); foreach ($languages as $langcode => $language) { $options[$langcode] = $language->getName(); } $form['language'] = array('#type' => 'radios', '#title' => t('Anonymous user preferred language'), '#default_value' => '', '#options' => $options, '#description' => t('New subscriptions will be subscribed with the selected preferred language. The language of existing subscribers is unchanged.')); } else { $form['language'] = array('#type' => 'value', '#value' => ''); } $form['submit'] = array('#type' => 'submit', '#value' => t('Subscribe')); return $form; }
/** * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { // To get the Cardinality value. $field_storage = FieldStorageConfig::loadByName('node', 'simplenews_issue'); $options = array(); foreach ($items as $key => $val) { $options[] = $val->target_id; } // Determining the type of the field. $element_type = "select"; // Cheking if it's UNLIMITED or not. if ($field_storage->getCardinality() != 1) { // Determining the field type from the issue setings if it is UNLIMITED. if ($this->getSetting('allow_multiple') == "1") { $element_type = 'checkboxes'; } } // Setting the field. $element += array('#type' => $element_type, '#default_value' => $options, '#options' => $this->getOptions(simplenews_newsletter_list())); // Add our custom validator. $element['#element_validate'][] = array(get_class($this), 'validateElement'); return $element; }