You are here

function simplenews_form_node_form_alter in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_form_node_form_alter()
  2. 8 simplenews.module \simplenews_form_node_form_alter()

Implements hook_form_FORM_ID_alter().

File

./simplenews.module, line 280
Simplenews node handling, sent email, newsletter block and general hooks.

Code

function simplenews_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Add Simplenews settings to simplenews newsletter node form.
  $node = $form_state
    ->getFormObject()
    ->getEntity();
  if (in_array($node
    ->getType(), simplenews_get_content_types())) {

    // Display warning if the node is currently being sent.
    if (!$node
      ->isNew()) {
      if ($node->simplenews_issue->status == SIMPLENEWS_STATUS_SEND_PENDING) {
        \Drupal::messenger()
          ->addWarning(t('This newsletter issue is currently being sent. Any changes will be reflected in the e-mails which have not been sent yet.'));
      }
    }
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['simplenews_token_help'] = [
        '#title' => t('Replacement patterns'),
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('These tokens can be used in all text fields except subject and will be replaced on-screen and in the email.'),
      ];
      $form['simplenews_token_help']['browser'] = [
        '#theme' => 'token_tree_link',
        '#token_types' => [
          'simplenews-newsletter',
          'simplenews-subscriber',
          'node',
        ],
      ];
    }
  }
}