function CollageFormatter::collageformatter_layout_box in Collage Formatter 8
Recursive function to build the layout.
Parameters
$images: array - array of referenced entities to display, keyed by delta entity referenced available via $entity->_referringItem
- @param $type boolean - TRUE for portrait (horizontal contact - vertical box type); FALSE for landscape (vertical contact - horizontal box type).
1 call to CollageFormatter::collageformatter_layout_box()
- CollageFormatter::collageformatter_render_collage in src/
Plugin/ Field/ FieldFormatter/ CollageFormatter.php - Returns renderable array of collages.
File
- src/
Plugin/ Field/ FieldFormatter/ CollageFormatter.php, line 581 - Contains \Drupal\collageformatter\src\Plugin\Field\FieldFormatter\CollageFormatter.
Class
- CollageFormatter
- Plugin implementation of the 'collageformatter' formatter.
Namespace
Drupal\collageformatter\Plugin\Field\FieldFormatterCode
function collageformatter_layout_box($images, $type) {
$box = [];
$count = count($images);
if ($count >= 2) {
$size1 = floor($count / 2);
$size2 = $count - $size1;
$images1 = array_slice($images, 0, $size1);
$images2 = array_slice($images, $size1, $size2);
$box = [
'box_type' => 'box',
'box_orientation' => $type ? 'vertical' : 'horizontal',
'pixel_check' => FALSE,
];
$box[1] = $this
->collageformatter_layout_box($images1, !$type);
$box[2] = $this
->collageformatter_layout_box($images2, !$type);
$box[1]['parent_box_orientation'] = $box[2]['parent_box_orientation'] = $box['box_orientation'];
$box[1]['pixel_check'] = FALSE;
$box[2]['pixel_check'] = TRUE;
if ($type) {
// Horizontal contact; vertical box type.
$dimensions = [
'width' => $box[1]['total_width'],
];
}
else {
// Vertical contact; horizontal box type.
$dimensions = [
'height' => $box[1]['total_height'],
];
}
$box[2] = $this
->collageformatter_scale_box($box[2], $dimensions);
if ($type) {
// Horizontal contact; vertical box type.
$box['total_height'] = $box[1]['total_height'] + $box[2]['total_height'];
$box['total_width'] = $box[1]['total_width'];
}
else {
// Vertical contact; horizontal box type.
$box['total_width'] = $box[1]['total_width'] + $box[2]['total_width'];
$box['total_height'] = $box[1]['total_height'];
}
$box[1]['parent_total_width'] = $box[2]['parent_total_width'] = $box['total_width'];
$box[1]['parent_total_height'] = $box[2]['parent_total_height'] = $box['total_height'];
$box[1]['siblings_total_width'] = $box[2]['total_width'];
$box[1]['siblings_total_height'] = $box[2]['total_height'];
$box[2]['siblings_total_width'] = $box[1]['total_width'];
$box[2]['siblings_total_height'] = $box[1]['total_height'];
}
elseif ($count == 1) {
$box = array_pop($images)->_referringItem
->getValue();
$box['pixel_check'] = FALSE;
}
return $box;
}