mirror of
https://github.com/a2nt/silverstripe-webpack.git
synced 2024-10-22 17:05:31 +02:00
FIX: minor fixtures
This commit is contained in:
parent
878feb96a3
commit
b6c20dbf8c
@ -48,25 +48,23 @@ class ElementImageWidget extends DataExtension
|
||||
{
|
||||
parent::updateCMSFields($fields);
|
||||
|
||||
$fields->insertBefore(
|
||||
'Image',
|
||||
LinkField::create('ImageLinkID', 'Link')
|
||||
);
|
||||
$fields->removeByName(['ImageLinkID', 'Resize']);
|
||||
|
||||
$fields->push(LinkField::create('ImageLinkID', 'Link'));
|
||||
|
||||
$this->owner->ImageHeight = $this->getHeight();
|
||||
|
||||
$heights = Config::inst()->get(__CLASS__, 'available_heights');
|
||||
$widths = Config::inst()->get(__CLASS__, 'available_widths');
|
||||
|
||||
$fields->replaceField('Resize', CheckboxField::create(
|
||||
$fields->push(CheckboxField::create(
|
||||
'Resize',
|
||||
'Would you like to scale image?'
|
||||
));
|
||||
|
||||
if (count($heights)) {
|
||||
$fields->removeByName(['ManualWidth','ImageWidth',]);
|
||||
$fields->replaceField(
|
||||
'ImageHeight',
|
||||
$fields->removeByName(['ManualWidth','ImageWidth', 'ImageHeight']);
|
||||
$fields->push(
|
||||
CompositeField::create(
|
||||
DropdownField::create(
|
||||
'ImageHeight',
|
||||
@ -140,4 +138,15 @@ class ElementImageWidget extends DataExtension
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
$title = $this->owner->getField('Title');
|
||||
$img = $this->owner->Image();
|
||||
if (!$title && $img) {
|
||||
$this->owner->setField('Title', $img->getTitle());
|
||||
}
|
||||
|
||||
parent::onBeforeWrite();
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,25 @@ class BannerWidget extends Widget
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private $_random;
|
||||
public function Random()
|
||||
{
|
||||
if (!$this->_random) {
|
||||
$this->_random = self::get()->filter('Enabled', true)->sort('RAND()')->first();
|
||||
}
|
||||
|
||||
return $this->_random;
|
||||
}
|
||||
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
$title = $this->getField('Title');
|
||||
$img = $this->Image();
|
||||
if (!$title && $img) {
|
||||
$this->setField('Title', $img->getTitle());
|
||||
}
|
||||
|
||||
parent::onBeforeWrite();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="image-element__image<% if $Resize %><% if $Height %> height{$Height}<% end_if %><% if $Width %> width{$Width}<% end_if %><% end_if %>">
|
||||
<img
|
||||
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
|
||||
data-lazy-src="$ImageResized.URL" class="img-responsive" alt="$Title.ATT"
|
||||
data-lazy-src="$ImageResized.URL" class="img-responsive" alt="$Title"
|
||||
/>
|
||||
</div>
|
||||
<% end_if %>
|
||||
|
Loading…
Reference in New Issue
Block a user