Skip to content

Commit

Permalink
Merge pull request #433 from UN-OCHA/UNO-817-view-mode
Browse files Browse the repository at this point in the history
[UNO-817] Paragraph view mode theme suggestion
  • Loading branch information
Lisa Corcoran authored Jan 24, 2024
2 parents 410681c + 8b07054 commit 161b185
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions html/modules/custom/unocha_paragraphs/unocha_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,20 @@ function unocha_paragraphs_form_node_form_alter(array &$form, FormStateInterface
$form['sticky']['#access'] = FALSE;
}
}

/**
* Implements hook_theme_suggestions_HOOK_alter() for 'paragraph'.
*
* Add a theme hook suggestion for the paragraph view mode field so that
* we can differentiate the paragraphs in the form when they are rendered as
* previews.
*/
function unocha_paragraphs_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
if (isset($variables['elements']['#view_mode'], $variables['elements']['#paragraph'])) {
$viewmode = $variables['elements']['#view_mode'];
$paragraph = $variables['elements']['#paragraph'];
if (!empty($paragraph->paragraph_view_mode?->value)) {
$suggestions[] = 'paragraph__' . $paragraph->bundle() . '__' . $viewmode . '__' . $paragraph->paragraph_view_mode->value;
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{% include '@common_design_subtheme/paragraphs/paragraph--reliefweb-river.html.twig' %}
{% include '@common_design_subtheme/paragraphs/paragraph--reliefweb-river.html.twig' with {
'attributes': attributes.addClass('paragraph--view-mode--' ~ paragraph.paragraph_view_mode.value)
}
%}

0 comments on commit 161b185

Please sign in to comment.