Skip to content

Commit f2f2b8f

Browse files
committed
Merge remote-tracking branch 'origin/feature/image_size' into hotfix/2.0.3
2 parents 6bc0b80 + ce37680 commit f2f2b8f

File tree

5 files changed

+132
-15
lines changed

5 files changed

+132
-15
lines changed

contao/config/event_listeners.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
* @filesource
2424
*/
2525

26+
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent;
2627
use MetaModels\Attribute\TranslatedFile\AttributeTypeFactory;
2728
use MetaModels\Attribute\Events\CreateAttributeFactoryEvent;
29+
use MetaModels\Events\Attribute\TranslatedFile\ImageSizeOptions;
2830
use MetaModels\MetaModelsEvents;
2931

3032
return array
@@ -35,4 +37,8 @@ function (CreateAttributeFactoryEvent $event) {
3537
$factory->addTypeFactory(new AttributeTypeFactory());
3638
}
3739
),
40+
41+
GetPropertyOptionsEvent::NAME => array(
42+
array(new ImageSizeOptions(), 'getPropertyOptions')
43+
)
3844
);

contao/dca/tl_metamodel_rendersetting.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
'reference' => &$GLOBALS['TL_LANG']['MSC'],
6969
'eval' => array(
7070
'rgxp' => 'digit',
71+
'includeBlankOption' => true,
7172
'nospace' => true,
7273
'helpwizard' => true,
7374
'tl_class' => 'w50',
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
<?php if (is_array($this->src)): ?>
22
<ul>
3-
<?php foreach($this->src as $arrFile):
3+
<?php foreach($this->src as $arrFile):
44
$strTitle = ($arrFile['title']) ? $arrFile['title'] : (($arrFile['alt']) ? $arrFile['alt'] : $arrFile['file']);
55
$strAlt = ($arrFile['caption']) ? $arrFile['caption'] : ''; ?>
66
<li class="<?php echo $arrFile['class']; ?>">
7-
<?php if ($this->settings->get('file_showLink')): ?>
7+
<?php if ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
8+
<figure class="image_container<?= $arrFile['floatClass'] ?>"<?php if ($arrFile['margin']): ?> style="<?= $arrFile['margin'] ?>"<?php endif; ?>>
9+
<?php endif; ?>
10+
<?php if ($this->settings->get('file_showLink')): ?>
811
<?php if ($this->settings->get('file_showImage')): ?>
912
<a class="cboxElement" data-lightbox="<?php echo $arrFile['lb']; ?>" title="<?php echo $strTitle; ?>" href="<?php echo $arrFile['file']; ?>">
1013
<?php else: ?>
1114
<a title="<?php echo $strTitle; ?>" href="<?php echo $arrFile['url']; ?>">
1215
<?php endif; ?>
1316
<?php endif; ?>
1417

15-
<?php if ($this->settings->get('file_showImage')): ?>
18+
<?php if (!$arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
1619
<?php if ($arrFile['isGdImage'] || $arrFile['isSvgImage']): ?>
1720
<?php echo $this->generateImage($arrFile['src'], $strAlt); ?>
1821
<?php endif; ?>
22+
<?php elseif ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
23+
<?php $this->insert('picture_default',$arrFile['picture']); ?>
1924
<?php else: ?>
2025
<img src="<?php echo $arrFile['icon']; ?>" alt="<?php echo $strAlt; ?>" /> <?php echo $strTitle; ?> <span class="size"><?php echo $arrFile['sizetext']; ?></span>
2126
<?php endif; ?>
2227

2328
<?php if ($this->settings->get('file_showLink')): ?>
2429
</a>
2530
<?php endif; ?>
31+
32+
<?php if ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
33+
<?php if ($arrFile['caption']): ?>
34+
<figcaption class="caption"><?= $arrFile['caption'] ?></figcaption>
35+
<?php endif; ?>
36+
</figure>
37+
<?php endif; ?>
2638
</li>
2739
<?php endforeach; ?>
2840
</ul>
29-
<?php endif; ?>
41+
<?php endif; ?>

contao/templates/mm_attr_translatedfile_alternative.html5

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
<?php if (is_array($this->src)): ?>
22
<?php foreach($this->src as $arrFile): ?>
33
<p class="<?= $arrFile['class'] ?><?= $this->additional_class ?>">
4+
<?php if ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
5+
<figure class="image_container<?= $arrFile['floatClass'] ?>"<?php if ($arrFile['margin']): ?> style="<?= $arrFile['margin'] ?>"<?php endif; ?>>
6+
<?php endif; ?>
47
<?php if ($this->settings->get('file_showLink')): ?>
5-
<?php if ($this->settings->get('file_showImage')): ?>
6-
<a class="cboxElement" data-lightbox="<?= $arrFile['lb'] ?>" title="<?= $arrFile['alt'] ?>" href="<?= $arrFile['file'] ?>">
7-
<?php else: ?>
8-
<a title="<?= $arrFile['alt'] ?>" href="<?= $arrFile['url'] ?>">
9-
<?php endif; ?>
8+
<?php if ($this->settings->get('file_showImage')): ?>
9+
<a class="cboxElement" data-lightbox="<?= $arrFile['lb'] ?>" title="<?= $arrFile['alt'] ?>" href="<?= $arrFile['file'] ?>">
10+
<?php else: ?>
11+
<a title="<?= $arrFile['alt'] ?>" href="<?= $arrFile['url'] ?>">
12+
<?php endif; ?>
1013
<?php endif; ?>
11-
<?php if ($this->settings->get('file_showImage')): ?>
12-
<?php if ($arrFile['isGdImage'] || $arrFile['isSvgImage']): ?>
13-
<?= $this->generateImage($arrFile['src'], $arrFile['caption']) ?>
14-
<?php endif; ?>
14+
<?php if (!$arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
15+
<?php if ($arrFile['isGdImage'] || $arrFile['isSvgImage']): ?>
16+
<?= $this->generateImage($arrFile['src'], $arrFile['caption']) ?>
17+
<?php endif; ?>
18+
<?php elseif ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
19+
<?php $this->insert('picture_default',$arrFile['picture']); ?>
1520
<?php else: ?>
16-
<img src="<?= $arrFile['icon'] ?>" alt="" /> <?= $arrFile['alt'] ? $arrFile['alt'] : $arrFile['file'] ?> <span class="size"><?= $arrFile['sizetext'] ?></span>
21+
<img src="<?= $arrFile['icon'] ?>" alt="" /> <?= $arrFile['alt'] ? $arrFile['alt'] : $arrFile['file'] ?> <span class="size"><?= $arrFile['sizetext'] ?></span>
1722
<?php endif; ?>
1823
<?php if ($this->settings->get('file_showLink')): ?>
19-
</a>
24+
</a>
25+
<?php endif; ?>
26+
<?php if ($arrFile['isPicture'] && $this->settings->get('file_showImage')): ?>
27+
<?php if ($arrFile['caption']): ?>
28+
<figcaption class="caption"><?= $arrFile['caption'] ?></figcaption>
29+
<?php endif; ?>
30+
</figure>
2031
<?php endif; ?>
2132
</p>
2233
<?php endforeach; ?>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* This file is part of MetaModels/attribute_translatedfile.
5+
*
6+
* (c) 2012-2018 The MetaModels team.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* This project is provided in good faith and hope to be usable by anyone.
12+
*
13+
* @package MetaModels
14+
* @subpackage AttributeFile
15+
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
16+
* @author Sven Baumann ≤baumann.sv@gmail.com>
17+
* @copyright 2012-2018 The MetaModels team.
18+
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
19+
* @filesource
20+
*/
21+
22+
namespace MetaModels\Events\Attribute\TranslatedFile;
23+
24+
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetPropertyOptionsEvent;
25+
use ContaoCommunityAlliance\DcGeneral\Data\DefaultDataProvider;
26+
27+
/**
28+
* Get the options for the image size.
29+
*/
30+
class ImageSizeOptions
31+
{
32+
/**
33+
* Get property options for file image size in the render settings.
34+
*
35+
* @param GetPropertyOptionsEvent $event The event.
36+
*/
37+
public function getPropertyOptions(GetPropertyOptionsEvent $event)
38+
{
39+
if (('file_imageSize' !== $event->getPropertyName())
40+
|| ('tl_metamodel_rendersetting' !== $event->getEnvironment()->getDataDefinition()->getName())
41+
) {
42+
return;
43+
}
44+
45+
$sizes = $this->getThemeImageSizes();
46+
if (!$sizes) {
47+
return;
48+
}
49+
50+
$options = $event->getOptions();
51+
$options['image_sizes'] = array_replace($sizes, (array) $options['image_sizes']);
52+
53+
$event->setOptions($options);
54+
}
55+
56+
/**
57+
* Get the image sizes from the theme.
58+
*
59+
* @return array
60+
*/
61+
private function getThemeImageSizes()
62+
{
63+
$dataProvider = new DefaultDataProvider();
64+
$dataProvider->setBaseConfig(array('source' => 'tl_image_size'));
65+
66+
$config = $dataProvider->getEmptyConfig();
67+
$config->setFields(array('id', 'name', 'width', 'height'));
68+
$config->setSorting(array('pid', 'name'));
69+
70+
$collection = $dataProvider->fetchAll($config);
71+
if (!$collection->count()) {
72+
return array();
73+
}
74+
75+
$sizes = array();
76+
foreach ($collection as $model) {
77+
$sizes[$model->getProperty('id')] = sprintf(
78+
'%s (%sx%s)',
79+
$model->getProperty('name'),
80+
$model->getProperty('width'),
81+
$model->getProperty('height')
82+
);
83+
}
84+
85+
return $sizes;
86+
}
87+
}

0 commit comments

Comments
 (0)