function farm_theme_entity_view_alter in farmOS 7
Implements hook_entity_view_alter().
File
- themes/
farm_theme/ template.php, line 307 - Farm theme template.php.
Code
function farm_theme_entity_view_alter(&$build, $type) {
// If the entity is not a farm_asset or farm_plan, bail.
if (!in_array($type, array(
'farm_asset',
'farm_plan',
))) {
return;
}
// If certain elements exist, we will split the page into two columns and
// put them in the right column, and everything else in the left.
$right_elements = array(
'inventory',
'weight',
'group',
'location',
'farm_plan_map',
);
$right_elements_exist = FALSE;
foreach ($right_elements as $name) {
if (!empty($build[$name])) {
$right_elements_exist = TRUE;
break;
}
}
if ($right_elements_exist) {
// Create a new container div that spans half of the grid.
$build['right'] = array(
'#type' => 'container',
'#prefix' => '<div class="col-md-6">',
'#suffix' => '</div>',
'#weight' => -99,
);
// Move the elements into the container.
foreach ($right_elements as $name) {
if (!empty($build[$name])) {
$build['right'][$name] = $build[$name];
unset($build[$name]);
}
}
// Put everything else into another div and move it to the top so it
// aligns left.
$build['left'] = array(
'#prefix' => '<div class="col-md-6">',
'#suffix' => '</div>',
'#weight' => -100,
);
$elements = element_children($build);
foreach ($elements as $element) {
if (!in_array($element, array(
'left',
'right',
'views',
))) {
$build['left'][$element] = $build[$element];
unset($build[$element]);
}
}
// Wrap the Views in a full-width div at the bottom.
if (!empty($build['views'])) {
$build['views']['#prefix'] = '<div class="col-md-12">';
$build['views']['#suffix'] = '</div>';
$build['views']['#weight'] = 101;
}
}
}