You are here

function template_preprocess_recipe_view_recipeml in Recipe 8.2

Prepares variables for the RecipeML style template.

Default template: recipe-view-recipeml.html.twig.

Parameters

array $variables: An associative array containing:

  • view: A ViewExecutable object.
  • rows: The raw row data.

File

./recipe.module, line 404
Contains functions for Recipe node CRUD and display.

Code

function template_preprocess_recipe_view_recipeml(&$variables) {
  $variables['recipes'] = $variables['rows'];

  // During live preview we don't want to output the header since the contents
  // of the RecipeML are being displayed inside a normal HTML page.
  if (empty($variables['view']->live_preview)) {
    $variables['view']
      ->getResponse()->headers
      ->set('Content-Type', 'text/xml; charset=utf-8');
  }

  // Add the language xml:lang attribute to each recipe.
  foreach ($variables['recipes'] as $key => $recipe) {
    $variables['recipes'][$key]['attributes'] = new Attribute([
      'xml:lang' => $recipe['langcode'],
    ]);
  }
}