materio_simplenews.module 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. function materio_simplenews_entity_type_alter(array &$entity_types) {
  3. $entity_types['simplenews_subscriber']->setFormClass('materio_block', '\Drupal\materio_simplenews\Form\MaterioSubscriptionsBlockForm');
  4. }
  5. /**
  6. * Implements hook_form_alter().
  7. */
  8. // node_simplenews_issue_edit_form
  9. // function materio_simplenews_form_alter(&$form, &$form_state, $form_id) {
  10. function materio_simplenews_form_node_simplenews_issue_form_alter(&$form, &$form_state, $form_id) {
  11. if(isset($_REQUEST['newsletter'])){
  12. $news_id = $_REQUEST['newsletter'];
  13. $newsletters = array_keys(simplenews_newsletter_get_all());
  14. if(in_array($news_id, $newsletters)){
  15. // prepopulate type of news
  16. $form['simplenews_issue']['widget']['target_id']['#default_value'] = $news_id;
  17. $form['simplenews_issue']['widget']['target_id']['#disabled'] = true;
  18. unset($form['simplenews_issue']['widget']['target_id']['#ajax']);
  19. // change default template regarding type of news
  20. $form['body']['widget'][0]['#default_value'] = materio_simplenews_getSimplenewsNodeBodyTemplate($news_id);
  21. $form['body']['widget'][0]['#rows'] = 50;
  22. $form['body']['widget'][0]['#format'] = 'full_html';
  23. }
  24. }
  25. }
  26. function materio_simplenews_getSimplenewsNodeBodyTemplate($news_id){
  27. return file_get_contents(\Drupal::service('extension.list.module')->getPath('materio_simplenews').'/templates/simplenews_'.$news_id.'_node.html');
  28. }
  29. function materio_simplenews_form_node_simplenews_issue_edit_form_alter(&$form, &$form_state, $form_id) {
  30. $default = $form['simplenews_issue']['widget']['target_id']['#default_value'];
  31. $form['simplenews_issue']['widget']['target_id']['#default_value'] = $default[0];
  32. $form['simplenews_issue']['widget']['target_id']['#disabled'] = true;
  33. }