You are here

function social_landing_page_preprocess_paragraph in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  2. 8 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  3. 8.2 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  4. 8.3 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  5. 8.4 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  6. 8.6 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  7. 8.7 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  8. 8.8 modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  9. 10.3.x modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  10. 10.0.x modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  11. 10.1.x modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()
  12. 10.2.x modules/social_features/social_landing_page/social_landing_page.module \social_landing_page_preprocess_paragraph()

Prepares variables for the paragraph.

File

modules/social_features/social_landing_page/social_landing_page.module, line 171
The Social landing page module.

Code

function social_landing_page_preprocess_paragraph(&$variables) {

  /** @var \Drupal\paragraphs\Entity\Paragraph $entity */
  $entity = $variables['elements']['#paragraph'];
  $bundle = $entity
    ->bundle();
  switch ($bundle) {
    case 'hero':

      // Add the hero styled image.
      $image_style = 'social_landing_hero';
      $image_field = "field_{$bundle}_image";
      if ($entity
        ->hasField($image_field) && !empty($entity->{$image_field}->entity)) {
        $variables['hero_styled_image_url'] = ImageStyle::load($image_style)
          ->buildUrl($entity->{$image_field}->entity
          ->getFileUri());
      }
      break;
    case 'hero_small':

      // Add the hero styled image.
      $image_style = 'social_landing_hero_small';
      $image_field = "field_{$bundle}_image";
      if ($entity
        ->hasField($image_field) && !empty($entity->{$image_field}->entity)) {
        $variables['hero_small_styled_image_url'] = ImageStyle::load($image_style)
          ->buildUrl($entity->{$image_field}->entity
          ->getFileUri());
      }
      break;
  }
}