Skip to content

Commit

Permalink
Add size for external images
Browse files Browse the repository at this point in the history
- defaults to 128
  • Loading branch information
zoglo committed Apr 12, 2024
1 parent 03930cd commit 756ee0e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
18 changes: 16 additions & 2 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'recommendation_activate';

// Add palettes to tl_module
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationlist'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives,recommendation_readerModule,recommendation_minRating,recommendation_featured,recommendation_order,numberOfItems,perPage;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationreader'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationlist'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives,recommendation_readerModule,recommendation_minRating,recommendation_featured,recommendation_order,numberOfItems,perPage;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationreader'] = '{title_legend},name,headline,type;{config_legend},recommendation_archives;{template_legend:hide},recommendation_metaFields,recommendation_template,customTpl;{image_legend:hide},imgSize,recommendation_externalSize;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['recommendationform'] = '{title_legend},name,headline,type;{config_legend},recommendation_archive,recommendation_optionalFormFields,recommendation_customFieldLabel,recommendation_notify,recommendation_moderate,recommendation_disableCaptcha;{privacy_legend},recommendation_privacyText;{redirect_legend:hide},jumpTo;{email_legend:hide},recommendation_activate;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';

$GLOBALS['TL_DCA']['tl_module']['subpalettes']['recommendation_activate'] = 'recommendation_activateJumpTo,recommendation_activateText';
Expand Down Expand Up @@ -178,6 +178,20 @@
'sql' => "varchar(64) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_template'] = [
'exclude' => true,
'inputType' => 'select',
'options_callback' => static fn () => Controller::getTemplateGroup('recommendation_'),
'eval' => ['includeBlankOption' => true, 'chosen' => true, 'tl_class'=>'w50'],
'sql' => "varchar(64) NOT NULL default ''"
];

$GLOBALS['TL_DCA']['tl_module']['fields']['recommendation_externalSize'] = [
'inputType' => 'text',
'eval' => ['multiple'=>true, 'size'=>2, 'rgxp'=>'natural', 'nospace'=>true, 'tl_class'=>'w50'],
'sql' => "varchar(64) COLLATE ascii_bin NOT NULL default ''"
];

class tl_module_recommendation extends Backend
{
/**
Expand Down
8 changes: 8 additions & 0 deletions contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
<source>Here you can select the recommendation template.</source>
<target>Hier können Sie das Bewertungstemplate auswählen.</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_externalSize.0">
<source>External size</source>
<target>Externe Größe</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_externalSize.1">
<source>Width and height of the external images in pixels (e.g. 128x128).</source>
<target>Breite und Höhe der externen Bilder in Pixeln (z. B. 128x128).</target>
</trans-unit>
<trans-unit id="tl_module.recommendation_order.0">
<source>Sort order</source>
<target>Sortierreihenfolge</target>
Expand Down
6 changes: 6 additions & 0 deletions contao/languages/en/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<trans-unit id="tl_module.recommendation_template.1">
<source>Here you can select the recommendation template.</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_externalSize.0">
<source>External size</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_externalSize.1">
<source>Width and height of the external images in pixels (e.g. 128x128).</source>
</trans-unit>
<trans-unit id="tl_module.recommendation_order.0">
<source>Sort order</source>
</trans-unit>
Expand Down
12 changes: 12 additions & 0 deletions contao/modules/ModuleRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @property string $recommendation_template
* @property mixed $recommendation_metaFields
* @property mixed $recommendation_externalSize
*/
abstract class ModuleRecommendation extends Module
{
Expand Down Expand Up @@ -151,6 +152,17 @@ protected function parseRecommendation(RecommendationModel $objRecommendation, R
$this->addInternalImage($objModel, $objTemplate);
}

$size = StringUtil::deserialize($this->recommendation_externalSize);
$width = $height = 128;

if (\is_array($size) && !empty($size[0]) && !empty($size[1]))
{
$width = $size[0];
$height = $size[1];
}

$objTemplate->externalSize = ' width="' . $width . '" height="' . $height . '"';

// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['parseRecommendation']) && \is_array($GLOBALS['TL_HOOKS']['parseRecommendation']))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?php $this->insert('image', $this->arrData); ?>
<?php elseif ($this->addExternalImage): ?>
<figure class="image_container">
<img src="<?= $this->imageUrl ?>" width="128" height="128" itemprop="image">
<img src="<?= $this->imageUrl ?>"<?= $this->externalSize ?> itemprop="image">
</figure>
<?php endif; ?>
<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion contao/templates/recommendation/recommendation_full.html5
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<?php $this->insert('image', $this->arrData); ?>
<?php elseif ($this->addExternalImage): ?>
<figure class="image_container">
<img src="<?= $this->imageUrl ?>" width="128" height="128" itemprop="image">
<img src="<?= $this->imageUrl ?>"<?= $this->externalSize ?> itemprop="image">
</figure>
<?php endif; ?>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?php $this->insert('image', $this->arrData); ?>
<?php elseif ($this->addExternalImage): ?>
<figure class="image_container">
<img src="<?= $this->imageUrl ?>" width="128" height="128" itemprop="image">
<img src="<?= $this->imageUrl ?>"<?= $this->externalSize ?> itemprop="image">
</figure>
<?php endif; ?>

Expand Down

0 comments on commit 756ee0e

Please sign in to comment.