-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaplings_paragraphs.module
48 lines (40 loc) · 1.33 KB
/
saplings_paragraphs.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
<?php
/**
* @file
* Contains saplings_paragraphs.module.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements template_preprocess_paragraph() for preview view mode.
*/
function saplings_paragraphs_preprocess_paragraph__preview(array &$variables) {
$paragraph = $variables['paragraph'];
$field_label = '';
if ($paragraph->hasField('sa_label') && !$paragraph->sa_label->isEmpty()) {
$field_label = $paragraph->sa_label->value;
}
$summary_items = $paragraph->getSummaryItems();
if ($field_label) {
$summary_items['content'] = [$field_label];
}
// Overwrite content variables with the summary.
$variables['content'] = [
'summary' => [
'#theme' => 'paragraphs_summary',
'#summary' => $summary_items,
],
];
}
/**
* Implements hook_field_widget_single_element_WIDGET_TYPE_form_alter().
*/
function saplings_paragraphs_field_widget_single_element_paragraphs_form_alter(array &$element, FormStateInterface $form_state, array $context) {
if (isset($element['preview'])) {
// Paragraphs role visibility might have denied access. Set this to true
// to always allow access to the preview in an admin context.
$element['preview']['#access'] = TRUE;
// Move preview into top summary.
$element['top']['summary']['preview'] = $element['preview'];
unset($element['preview']);
}
}