Skip to content

Commit

Permalink
FEATURE Image position options (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Aug 14, 2024
1 parent c96d9fa commit e6018e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
22 changes: 16 additions & 6 deletions src/Element/ElementCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ElementCard extends BaseElement
*/
private static array $db = [
'Content' => 'HTMLText',
'Position' => 'Enum("Left, Right, Top", "Left")',
];

/**
Expand Down Expand Up @@ -90,6 +91,9 @@ public function fieldLabels($includerelations = true)
$labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Title');
$labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Description');
$labels['ElementLink'] = _t(__CLASS__ . '.ElementLinkLabel', 'Link');
$labels['Position'] = _t(__CLASS__ . '.PositionLabel', 'Image Position');
$labels['Image'] = _t(__CLASS__ . '.Image', 'Image');


return $labels;
}
Expand All @@ -101,14 +105,20 @@ public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
// @phpstan-ignore-next-line
$fields->dataFieldByName('Image')
->setFolderName('Uploads/Elements/Card');

$fields->insertBefore('Content', $fields->dataFieldByName('Image'));
$fields->dataFieldByName('Content')
->setRows(8);

// @phpstan-ignore-next-line
$fields->dataFieldByName('Content')
->setRows(5);
$fields->dataFieldByName('Image')
->setFolderName('Uploads/Elements/Card');
$fields->insertBefore('Position', $fields->dataFieldByName('Image'));

$fields->dataFieldByName('Position')
->setDescription(_t(
__CLASS__ . 'PositionDescription',
'Position of the image in relation to the content.
Image will display on top at smaller breakpoints.'
));

$fields->replaceField(
'ElementLinkID',
Expand Down
28 changes: 18 additions & 10 deletions templates/Dynamic/Elements/Card/Elements/ElementCard.ss
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<div class="element__card">
<div class="card h-100">
<div class="card h-100">
<div class="row g-0">
<% if $Image %>
<% if $ElementLink %><a href="$ElementLink.LinkURL" title="Go to $ElementLink.Title.ATT"><% end_if %>
<img src="$Image.FocusFill(500,330).URL" class="card-img-top" alt="$Image.Title.ATT">
<% if $ElementLink %></a><% end_if %>
<% if $Position == 'Top' %>
<img src="$Image.FocusFill(800,530).URL" class="card-img-top" alt="$Image.Title.ATT">
<% else %>
<div class="col-lg-7">
<img src="$Image.FocusFill(800,530).URL" class="img-fluid" alt="$Image.Title.ATT">
</div>
<% end_if %>
<% end_if %>
<div class="card-body">
<% if $Title && $ShowTitle %><$TitleTag class="element__title $TitleSizeClass">$Title</$TitleTag><% end_if %>
<% if $Content %><div class="card-text">$Content</div><% end_if %>
<% if $ElementLink %><p><a href="$ElementLink.URL" class="btn btn-primary" title="$ElementLink.Title"<% if $ElementLink.OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>$ElementLink.Title</a></p><% end_if %>
<div class="<% if $Position != 'Top' %> col-lg-5<% end_if %><% if $Position == 'Right' %> order-md-first<% end_if %>">
<div class="card-body h-100 d-flex align-items-center">
<div>
<% if $Title && $ShowTitle %><$TitleTag class="element__title $TitleSizeClass">$Title</$TitleTag><% end_if %>
<% if $Content %><div class="card-text">$Content</div><% end_if %>
<% if $ElementLink %><p><a href="$ElementLink.URL" class="btn btn-primary" title="$ElementLink.Title"<% if $ElementLink.OpenInNew %> target="_blank" rel="noopener noreferrer"<% end_if %>>$ElementLink.Title</a></p><% end_if %>
</div>
</div>
</div>
</div>
</div>
</div>

0 comments on commit e6018e7

Please sign in to comment.