public function RecipeML::render in Recipe 8.2
Render the display in this style.
Overrides StylePluginBase::render
File
- src/
Plugin/ views/ style/ RecipeML.php, line 202 - Copyright (c) FormatData. All rights reserved.
Class
- RecipeML
- Default style plugin to render RecipeML.
Namespace
Drupal\recipe\Plugin\views\styleCode
public function render() {
$view_fields_labels = $this->displayHandler
->getFieldLabels();
$rows = [];
foreach ($this->view->result as $row_index => $row) {
$this->view->row_index = $row_index;
$time_fields = [];
$total_time = 0;
foreach ($this->options['time_fields'] as $time_field) {
if (empty($time_field)) {
continue;
}
$time_value = $this
->getField($row_index, $time_field);
$time_fields[] = [
'type' => $view_fields_labels[$time_field],
'qty' => $time_value,
'timeunit' => 'minutes',
];
$total_time += (int) $time_value
->__toString();
}
// Add a total time field if there is more than one time_field.
if (count($time_fields) > 1) {
$time_fields[] = [
'type' => 'Total time',
'qty' => $total_time,
'timeunit' => 'minutes',
];
}
$rows[] = [
'langcode' => $row->_entity
->language()
->getId(),
'title' => $this
->getField($row_index, $this->options['title_field']),
'version' => $this
->getField($row_index, $this->options['version_field']),
'source' => $this
->getField($row_index, $this->options['source_field']),
'time_fields' => $time_fields,
'yield_qty' => $this
->getField($row_index, $this->options['yield_qty_field']),
'yield_unit' => $this
->getField($row_index, $this->options['yield_unit_field']),
'description' => $this
->getField($row_index, $this->options['description_field']),
'ingredients' => $this
->getField($row_index, $this->options['ingredients_field']),
'directions' => $this
->getField($row_index, $this->options['directions_field']),
];
}
$build = [
'#theme' => $this
->themeFunctions(),
'#view' => $this->view,
'#options' => $this->options,
'#rows' => $rows,
];
unset($this->view->row_index);
return $build;
}