This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtide_news.module
102 lines (90 loc) · 3.01 KB
/
tide_news.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @file
* Tide News module.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_entity_bundle_create().
*/
function tide_news_entity_bundle_create($entity_type_id, $bundle) {
// Enable News in Editorial workflow if workflow module is enabled.
if ($entity_type_id === 'node' && $bundle === 'news') {
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('workflows')) {
$editorial_workflow = Workflow::load('editorial');
if ($editorial_workflow) {
$editorial_workflow->getTypePlugin()
->addEntityTypeAndBundle('node', 'news');
$editorial_workflow->save();
}
}
}
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function tide_news_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (!in_array($form_id, [
'node_news_form',
'node_news_edit_form',
'node_news_quick_node_clone_form',
])) {
return;
}
if (isset($form['title']['widget'][0]['value']['#description'])) {
$form['title']['widget'][0]['value']['#description'] = t('Include a short unique title for your page and keywords.');
}
// Hide the body summary subfield in favour of the new Summary field.
if (!empty($form['body']['widget'])) {
foreach (Element::children($form['body']['widget']) as $delta) {
if (!empty($form['body']['widget'][$delta]['summary'])) {
$form['body']['widget'][$delta]['summary']['#access'] = FALSE;
}
}
}
// Change form layout.
$form['#attached']['library'][] = 'tide_news/news_form';
$form['#attributes']['class'][] = 'node-form-news';
$form['#process'][] = '_tide_news_form_node_form_process';
}
/**
* Node form #process callback.
*
* @param array $form
* Form that is being processed.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form.
*
* @return array
* The processed form.
*/
function _tide_news_form_node_form_process(array $form, FormStateInterface $form_state, array $complete_form = []) {
/** @var \Drupal\node\NodeInterface $node */
$node = $form_state->getFormObject()->getEntity();
$form['field_node_department']['#group'] = 'group_author_detail';
// At this stage, the form has not been fully built yet, so we need an
// after_build callback to determine the actual state.
$form['#after_build'][] = '_tide_news_form_node_form_after_build';
return $form;
}
/**
* Node form #after_build callback.
*
* @param array $form
* Form that is being processed.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The processed form.
*/
function _tide_news_form_node_form_after_build(array $form, FormStateInterface $form_state) {
$form['field_node_department']['#group'] = 'group_author_detail';
return $form;
}