Skip to content

Commit

Permalink
Issue #6736: Hero background img preview
Browse files Browse the repository at this point in the history
  • Loading branch information
docwilmot committed Nov 8, 2024
1 parent c402d68 commit 8e35300
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/modules/layout/includes/block.hero.inc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BlockHero extends BlockText {
'#upload_location' => 'public://hero/',
'#upload_validators' => $upload_validators,
'#weight' => -10,
'#theme' => 'layout_hero_background_image',
);
// Store the image path separately.
$form['image_path'] = array(
Expand Down
3 changes: 3 additions & 0 deletions core/modules/layout/layout.module
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,9 @@ function layout_theme() {
'template' => 'templates/layout-content-form',
'render element' => 'form',
) + $base,
'layout_hero_background_image' => array(
'render element' => 'element',
) + $base,
'layout_info' => array(
'variables' => array('layout' => NULL),
) + $base,
Expand Down
28 changes: 28 additions & 0 deletions core/modules/layout/layout.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,34 @@ function theme_layout_region_inner($variables) {
return implode('', $variables['blocks']);
}


/**
* Output a preview of hero block background image.
*/
function theme_layout_hero_background_image($variables) {
$element = $variables['element'];
$attributes = array();
if (isset($element['#id'])) {
$attributes['id'] = $element['#id'];
}
if (!empty($element['#attributes']['class'])) {
$attributes['class'] = (array) $element['#attributes']['class'];
}
$attributes['class'][] = 'form-managed-file';

$output = '';
$output .= '<div' . backdrop_attributes($attributes) . '>';
if (isset($element['#file']->uri)) {
$output .= '<div class="hero-bg-preview">';
$output .= '<img style="height:250px" src="' . image_style_url('medium', $element['#file']->uri) . '" />';
$output .= '</div>';
}
$output .= backdrop_render_children($element);
$output .= '</div>';

return $output;
}

/**
* Prepares variables for layout templates.
*
Expand Down

0 comments on commit 8e35300

Please sign in to comment.