function UmamiHooks::preprocessNodeRecipeFull

Implements hook_preprocess_HOOK() for node--recipe--full.

The recipe design closes with a listing of recipes from the same category. It is rendered by the template rather than placed in a region so that it stays inside the recipe itself.

Attributes

#[Hook('preprocess_node__recipe__full')]

File

core/profiles/demo_umami/themes/umami/src/Hook/UmamiHooks.php, line 77

Class

UmamiHooks
Hook implementations for umami.

Namespace

Drupal\umami\Hook

Code

public function preprocessNodeRecipeFull(&$variables) : void {
  $view = Views::getView('related_recipes');
  if (!$view) {
    return;
  }
  $build = $view->buildRenderable('related_recipes_block');
  // Render the view now, so that a recipe with no related recipes shows
  // neither the listing nor its heading. Keep the cacheability that explains
  // why the listing is empty.
  // @see \Drupal\views\Plugin\Block\ViewsBlock::build()
  $build = View::preRenderViewElement($build);
  if (empty($build['view_build'])) {
    // Nothing to show. Keep the cacheability that says why, so that the
    // recipe is rebuilt once a related recipe exists.
    CacheableMetadata::createFromRenderArray($build)->merge(CacheableMetadata::createFromRenderArray($variables))
      ->applyTo($variables);
    return;
  }
  $variables['related_recipes'] = $build;
  $variables['related_recipes_title'] = $view->getTitle();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.