You are here

function template_preprocess_recipe_duration in Recipe 8.2

Prepares variables for the recipe duration template.

Default template: recipe-duration.html.twig.

Parameters

array $variables: An associative array containing:

  • duration: The total time duration in minutes.

File

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

Code

function template_preprocess_recipe_duration(&$variables) {
  $hours = floor($variables['duration'] / 60);
  $minutes = $variables['duration'] % 60;
  $variables['hours'] = '';
  $variables['minutes'] = '';
  if ($hours > 0) {
    $variables['hours'] = \Drupal::translation()
      ->formatPlural($hours, '1 hour', '@count hours');
  }
  if ($minutes > 0 || $variables['duration'] == 0) {
    $variables['minutes'] = \Drupal::translation()
      ->formatPlural($minutes, '1 minute', '@count minutes');
  }
}