forked from justin2pin/layout_paragraphs_editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayout_paragraphs_editor.module
99 lines (95 loc) · 2.95 KB
/
layout_paragraphs_editor.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
<?php
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function layout_paragraphs_editor_theme() {
return [
'layout_paragraphs' => [
'variables' => [
'elements' => '',
'content' => '',
],
],
'layout_paragraphs_editor_item' => [
'render element' => 'element',
],
'layout_paragraphs_editor_banner' => [
'variables' => [
'save_url' => NULL,
'cancel_url' => NULL,
'title' => NULL,
],
],
'layout_paragraphs_editor_controls' => [
'variables' => [],
],
'layout_paragraphs_editor_component_menu' => [
'variables' => [
'types' => NULL,
],
],
'layout_paragraphs_editor_section_menu' => [
'variables' => [
'types' => NULL,
],
],
'layout_paragraphs_editor_empty_container' => [
'variables' => [],
],
'layout_paragraphs_editor_enable' => [
'variables' => [
'url' => NULL,
'is_empty' => NULL,
'title' => NULL,
'field_name' => NULL,
'field_label' => NULL,
],
],
'field__layout_paragraphs_editor' => [
'template' => 'field--layout-paragraphs-editor',
'base hook' => 'field',
],
];
}
/**
* Add needed attributes when editing a layout paragraphs layout.
*
* @param array $variables
* The variables.
*/
function layout_paragraphs_editor_preprocess_paragraph(array &$variables) {
$route_name = \Drupal::routeMatch()->getRouteName();
if (strpos($route_name, 'layout_paragraphs_editor.editor') === 0) {
$variables['attributes']['data-uuid'] = $variables['paragraph']->uuid();
$variables['attributes']['data-id'] = $variables['paragraph']->id();
$variables['attributes']['class'][] = 'lpe-component';
$variables['attributes']['tabindex'] = 0;
if (!empty($variables['content']['regions'])) {
$variables['attributes']['class'][] = 'lpe-layout';
foreach (Element::children($variables['content']['regions']) as $region_name) {
$region =& $variables['content']['regions'][$region_name];
$region['placeholder'] = [
'#markup' => '<div data-lpe-empty-region> </div>',
];
$region['#attributes']['class'][] = 'lpe-region';
$region['#attributes']['data-region'] = $region_name;
$region['#attributes']['data-region-uuid'] = $variables['paragraph']->uuid() . '-' . $region_name;
$region['#attributes']['tabindex'] = 0;
}
}
}
}
/**
* Implements hook_theme_suggestions_field_alter().
*/
function layout_paragraphs_theme_suggestions_field_alter(&$suggestions, $variables) {
$route_name = \Drupal::routeMatch()->getRouteName();
if (strpos($route_name, 'layout_paragraphs_editor.editor') === 0) {
if ($variables['element']['#formatter'] == 'layout_paragraphs_editor') {
$suggestions[] = 'field__layout_paragraphs_editor';
}
}
}