presto-8.x-2.2/modules/presto_components/presto_components.module
modules/presto_components/presto_components.module
<?php
/**
* @file
* The Presto Components module file.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements theme_hook().
*/
function presto_components_theme($existing, $type, $theme, $path) {
return [
'paragraph__component_divider' => [
'template' => 'paragraph--component-divider',
'base hook' => 'paragraph',
],
'paragraph__component_image' => [
'template' => 'paragraph--component-image',
'base hook' => 'paragraph',
],
'paragraph__component_promo_bar' => [
'template' => 'paragraph--component-promo-bar',
'base hook' => 'paragraph',
],
'paragraph__component_icon_box' => [
'template' => 'paragraph--component-icon-box',
'base hook' => 'paragraph',
],
'paragraph__component_icon_box_list' => [
'template' => 'paragraph--component-icon-box-list',
'base hook' => 'paragraph',
],
'paragraph__component_accordion' => [
'template' => 'paragraph--component-accordion',
'base hook' => 'paragraph',
],
'field__paragraph__field_accordion_panel' => [
'template' => 'field--paragraph--field-accordion-panel',
'base hook' => 'field',
],
'paragraph__component_accordion_panel' => [
'template' => 'paragraph--component-accordion-panel',
'base hook' => 'paragraph',
],
];
}
/**
* Implements theme_suggestions_paragraph_alter().
*/
function presto_components_theme_suggestions_paragraph_alter(array &$suggestions, array $variables, $hook) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['elements']['#paragraph'];
$type = $paragraph->getType();
$suggestions[] = "paragraph__{$type}";
}
/**
* Implements hook_form_alter().
*/
function presto_components_form_alter(
&$form,
FormStateInterface $form_state,
$form_id
) {
// Attached some JS to manage the conditional display for IconBox.
if (isset($form['field_body_paragraphs'])) {
$form['#attached']['library'][] = 'presto_components/iconbox_conditional_display';
}
}
/**
* Prepares variables for paragraph templates.
*
* Default template: paragraph.html.twig.
*
* Most themes use their own copy of paragraph.html.twig. The default is located
* inside "templates/paragraph.html.twig". Look in there for the
* full list of variables.
*
* @param array $variables
* An associative array containing:
* - elements: An array of elements to display in view mode.
* - paragraph: The paragraph object.
* - view_mode: View mode; e.g., 'full', 'teaser'...
*/
function presto_components_preprocess_paragraph(array &$variables) {
$paragraph = $variables['elements']['#paragraph'];
$type = $paragraph->getType();
$id = $paragraph->id();
$variables['paragraph_type_id'] = "{$type}_{$id}";
if ($type === 'component_accordion_panel') {
$parent_entity = $paragraph->getParentEntity();
$parent_type = $parent_entity->getType();
$parent_id = $parent_entity->id();
$variables['parent_paragraph_type_id'] = "{$parent_type}_{$parent_id}";
}
}
