Skip to content

Commit dcebae6

Browse files
authored
[5.1] Replace hard coded img element by JLayout joomla.html.image and DRY (#42508)
1 parent 82ff6b5 commit dcebae6

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

modules/mod_banners/tmpl/default.php

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Joomla\CMS\Helper\MediaHelper;
1414
use Joomla\CMS\HTML\HTMLHelper;
1515
use Joomla\CMS\Language\Text;
16+
use Joomla\CMS\Layout\LayoutHelper;
1617
use Joomla\CMS\Router\Route;
1718
use Joomla\CMS\Uri\Uri;
1819
?>
@@ -40,6 +41,17 @@
4041
<?php $alt = $alt ?: Text::_('MOD_BANNERS_BANNER'); ?>
4142
<?php $width = $item->params->get('width'); ?>
4243
<?php $height = $item->params->get('height'); ?>
44+
<?php $imageAttribs = [
45+
'src' => $baseurl . $imageurl,
46+
'alt' => $alt
47+
];?>
48+
<?php if (!empty($width)) : ?>
49+
<?php $imageAttribs['width'] = $width; ?>
50+
<?php endif; ?>
51+
<?php if (!empty($height)) : ?>
52+
<?php $imageAttribs['height'] = $height; ?>
53+
<?php endif; ?>
54+
<?php $image = LayoutHelper::render('joomla.html.image', $imageAttribs); ?>
4355
<?php if ($item->clickurl) : ?>
4456
<?php // Wrap the banner in a link ?>
4557
<?php $target = $params->get('target', 1); ?>
@@ -48,16 +60,7 @@
4860
<a
4961
href="<?php echo $link; ?>" target="_blank" rel="noopener noreferrer"
5062
title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8'); ?>">
51-
<img
52-
src="<?php echo $baseurl . $imageurl; ?>"
53-
alt="<?php echo htmlspecialchars($alt, ENT_QUOTES, 'UTF-8'); ?>"
54-
<?php if (!empty($width)) {
55-
echo 'width="' . $width . '"';
56-
} ?>
57-
<?php if (!empty($height)) {
58-
echo 'height="' . $height . '"';
59-
} ?>
60-
>
63+
<?php echo $image; ?>
6164
</a>
6265
<?php elseif ($target == 2) : ?>
6366
<?php // Open in a popup window ?>
@@ -66,46 +69,19 @@
6669
'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550');
6770
return false"
6871
title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8'); ?>">
69-
<img
70-
src="<?php echo $baseurl . $imageurl; ?>"
71-
alt="<?php echo htmlspecialchars($alt, ENT_QUOTES, 'UTF-8'); ?>"
72-
<?php if (!empty($width)) {
73-
echo 'width="' . $width . '"';
74-
} ?>
75-
<?php if (!empty($height)) {
76-
echo 'height="' . $height . '"';
77-
} ?>
78-
>
72+
<?php echo $image; ?>
7973
</a>
8074
<?php else : ?>
8175
<?php // Open in parent window ?>
8276
<a
8377
href="<?php echo $link; ?>"
8478
title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8'); ?>">
85-
<img
86-
src="<?php echo $baseurl . $imageurl; ?>"
87-
alt="<?php echo htmlspecialchars($alt, ENT_QUOTES, 'UTF-8'); ?>"
88-
<?php if (!empty($width)) {
89-
echo 'width="' . $width . '"';
90-
} ?>
91-
<?php if (!empty($height)) {
92-
echo 'height="' . $height . '"';
93-
} ?>
94-
>
79+
<?php echo $image; ?>
9580
</a>
9681
<?php endif; ?>
9782
<?php else : ?>
9883
<?php // Just display the image if no link specified ?>
99-
<img
100-
src="<?php echo $baseurl . $imageurl; ?>"
101-
alt="<?php echo htmlspecialchars($alt, ENT_QUOTES, 'UTF-8'); ?>"
102-
<?php if (!empty($width)) {
103-
echo 'width="' . $width . '"';
104-
} ?>
105-
<?php if (!empty($height)) {
106-
echo 'height="' . $height . '"';
107-
} ?>
108-
>
84+
<?php echo $image; ?>
10985
<?php endif; ?>
11086
<?php endif; ?>
11187
<?php endif; ?>

0 commit comments

Comments
 (0)