-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncms_publisher.module
50 lines (45 loc) · 1.45 KB
/
ncms_publisher.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* NCMS module file.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\ncms_ui\Entity\ContentInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function ncms_publisher_form_node_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\node\NodeForm $form_object */
$form_object = $form_state->getFormObject();
$entity = $form_object->getEntity();
if (!$entity instanceof ContentInterface) {
return;
}
foreach (array_keys($form['actions']) as $action) {
$action_type = $form['actions'][$action]['#type'] ?? NULL;
if ($action != 'preview' && $action_type === 'submit') {
$form['actions'][$action]['#submit'][] = 'ncms_publisher_content_base_edit_form_submit';
}
}
}
/**
* Custom submit function for the node article edit form.
*
* Checks if the edit request came from a trusted publisher and redirects back
* to it if requested.
*/
function ncms_publisher_content_base_edit_form_submit($form, FormStateInterface $form_state) {
/** @var \Drupal\ncms_publisher\PublisherManager $publisher_manager */
$publisher_manager = \Drupal::service('ncms_publisher.publisher.manager');
$response = $publisher_manager->getCurrentRedirectResponse();
if ($response) {
$form_state->setResponse($response);
// Cleanup messages.
\Drupal::messenger()->deleteAll();
}
else {
// Redirect to the front page.
$form_state->setRedirectUrl(Url::fromUserInput('/'));
}
}