Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE Image position options #6

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading