You are here

function simplenews_form_node_type_form_alter in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_form_node_type_form_alter()
  2. 8 simplenews.module \simplenews_form_node_type_form_alter()
  3. 7.2 simplenews.module \simplenews_form_node_type_form_alter()
  4. 7 simplenews.module \simplenews_form_node_type_form_alter()

Implements hook_form_FORM_ID_alter().

Add checkbox to the content type form to use the content type as newsletter.

File

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

Code

function simplenews_form_node_type_form_alter(array &$form, FormStateInterface $form_state) {

  // Add option to use content type as simplenews newsletter.
  $node_type = $form_state
    ->getFormObject()
    ->getEntity();

  // Get the default based on the existence of the simplenews_issue field.
  $default = FALSE;
  if (!$node_type
    ->isNew()) {
    $fields = \Drupal::service('entity_field.manager')
      ->getFieldDefinitions('node', $node_type
      ->id());
    $default = isset($fields['simplenews_issue']);
  }
  $form['workflow']['simplenews_content_type'] = [
    '#type' => 'checkbox',
    '#title' => t('Use as simplenews newsletter'),
    '#default_value' => $default,
    '#description' => t('This will add the simplenews issue field to this content type, allowing content of this type to be sent out as a newsletter issue.'),
  ];
  $form['actions']['submit']['#submit'][] = 'simplenews_form_node_type_submit';
  if (isset($form['actions']['save_continue'])) {
    $form['actions']['save_continue']['#submit'][] = 'simplenews_form_node_type_submit';
  }
}