Last active
December 10, 2021 11:39
-
-
Save levmyshkin/a69ac2486adfe020f5f3ef0432c11dfb to your computer and use it in GitHub Desktop.
Get paragraph type in preprocess_paragraph in drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements template_preprocess_paragraph(). | |
* | |
* @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 THEMENAME_preprocess_paragraph(&$variables) { | |
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */ | |
$paragraph = $variables['paragraph']; | |
// Get paragraph type | |
$parentBundle = $paragraph->bundle(); | |
if($parentBundle == 'slideshow') { | |
$variables['sitename'] = \Drupal::config('system.site')->get('name'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment