2020-12-28 16:40:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function materio_simplenews_entity_type_alter(array &$entity_types) {
|
|
|
|
$entity_types['simplenews_subscriber']->setFormClass('materio_block', '\Drupal\materio_simplenews\Form\MaterioSubscriptionsBlockForm');
|
|
|
|
}
|
2021-08-18 00:05:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_form_alter().
|
|
|
|
*/
|
|
|
|
// node_simplenews_issue_edit_form
|
|
|
|
// function materio_simplenews_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
function materio_simplenews_form_node_simplenews_issue_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
if(isset($_REQUEST['newsletter'])){
|
|
|
|
$news_id = $_REQUEST['newsletter'];
|
|
|
|
$newsletters = array_keys(simplenews_newsletter_get_all());
|
|
|
|
if(in_array($news_id, $newsletters)){
|
|
|
|
|
|
|
|
// prepopulate type of news
|
2021-08-18 01:03:31 +02:00
|
|
|
$form['simplenews_issue']['widget']['target_id']['#default_value'] = $news_id;
|
2021-08-18 00:05:12 +02:00
|
|
|
$form['simplenews_issue']['widget']['target_id']['#disabled'] = true;
|
2021-08-18 01:03:31 +02:00
|
|
|
unset($form['simplenews_issue']['widget']['target_id']['#ajax']);
|
|
|
|
|
2021-08-18 00:05:12 +02:00
|
|
|
// change default template regarding type of news
|
|
|
|
$form['body']['widget'][0]['#default_value'] = materio_simplenews_getSimplenewsNodeBodyTemplate($news_id);
|
|
|
|
$form['body']['widget'][0]['#rows'] = 50;
|
2021-08-24 19:28:08 +02:00
|
|
|
$form['body']['widget'][0]['#format'] = 'full_html';
|
2021-08-18 00:05:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function materio_simplenews_getSimplenewsNodeBodyTemplate($news_id){
|
2024-08-20 19:47:47 +02:00
|
|
|
return file_get_contents(\Drupal::service('extension.list.module')->getPath('materio_simplenews').'/templates/simplenews_'.$news_id.'_node.html');
|
2021-08-18 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function materio_simplenews_form_node_simplenews_issue_edit_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
$default = $form['simplenews_issue']['widget']['target_id']['#default_value'];
|
|
|
|
$form['simplenews_issue']['widget']['target_id']['#default_value'] = $default[0];
|
|
|
|
$form['simplenews_issue']['widget']['target_id']['#disabled'] = true;
|
2021-08-18 00:05:12 +02:00
|
|
|
}
|