You are here

function scs_form_node_form_alter in Simplenews Content Selection 8

Same name and namespace in other branches
  1. 7.2 scs.module \scs_form_node_form_alter()

Implements hook_form_FORM_ID_alter().

File

./scs.module, line 116
General hooks and commonly-used functions

Code

function scs_form_node_form_alter(&$form, &$form_state) {

  // Check that we are creating a newsletter and that we come from the
  // admin/content/node
  if (!empty($form['#node_edit_form']) && in_array($form['type']['#value'], simplenews_get_content_types()) && ($form_state['input']['op'] = t('Create newsletter') && isset($form_state['input']['nodes']))) {
    $nodes = \Drupal::entityTypeManager()
      ->getStorage('node')
      ->loadMultiple(array_keys($form_state['input']['nodes']));
    foreach ($nodes as $node) {
      $node->scs_view_mode = $form_state['input']['nodes'][$node->nid]['view_mode'];
    }
    $form['body'][LANGUAGE_NONE][0]['#default_value'] = theme('scs_newsletter', array(
      'nodes' => $nodes,
      'toc' => empty($form_state['input']['scs_toc']) ? FALSE : TRUE,
    ));
  }
}