-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_actions.module
More file actions
63 lines (53 loc) · 1.72 KB
/
Copy pathquick_actions.module
File metadata and controls
63 lines (53 loc) · 1.72 KB
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
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function quick_actions_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$node = $form_state->getFormObject()->getEntity();
$type = $node->bundle();
$enabled_types = ['page', 'article']; // placeholder - can be made configurable later
if (!in_array($type, $enabled_types)) {
return;
}
// Ensure vertical_tabs container exists.
if (!isset($form['advanced'])) {
$form['advanced'] = [
'#type' => 'vertical_tabs',
'#weight' => 99,
];
}
$form['quick_actions'] = [
'#type' => 'details',
'#title' => t('Quick actions'),
'#group' => 'advanced',
];
// Only show the link if the node has an ID.
if (!$node->isNew()) {
$form['quick_actions']['set_homepage'] = [
'#type' => 'link',
'#title' => t('Set as homepage'),
'#url' => Url::fromRoute('quick_actions.set_homepage', ['node' => $node->id()]),
'#description' => t("Use this action to set the current page as the site's front page. This can help promote important content."),
];
}
}
/**
* Implements hook_page_top().
*/
function quick_actions_page_top(array &$page_top) {
$current_path = \Drupal::service('path.current')->getPath();
$paths = \Drupal::config('quick_actions.settings')->get('default_paths') ?? [];
// Avoid duplicates.
if (in_array($current_path, $paths)) {
return;
}
$page_top['quick_actions_set_default'] = [
'#markup' => '<div id="set-as-default-button"><a href="#" class="set-as-default-link">Set as default</a></div>',
'#attached' => [
'library' => ['quick_actions/set_default'],
],
];
}