From e6018e7a33e28a167ec6ef2ae66566218261aa78 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Wed, 14 Aug 2024 14:08:35 -0500 Subject: [PATCH] FEATURE Image position options (#6) --- src/Element/ElementCard.php | 22 +++++++++++---- .../Elements/Card/Elements/ElementCard.ss | 28 ++++++++++++------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/Element/ElementCard.php b/src/Element/ElementCard.php index 979ef5e..e53580e 100644 --- a/src/Element/ElementCard.php +++ b/src/Element/ElementCard.php @@ -59,6 +59,7 @@ class ElementCard extends BaseElement */ private static array $db = [ 'Content' => 'HTMLText', + 'Position' => 'Enum("Left, Right, Top", "Left")', ]; /** @@ -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; } @@ -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', diff --git a/templates/Dynamic/Elements/Card/Elements/ElementCard.ss b/templates/Dynamic/Elements/Card/Elements/ElementCard.ss index d1b56e4..a7cd18a 100644 --- a/templates/Dynamic/Elements/Card/Elements/ElementCard.ss +++ b/templates/Dynamic/Elements/Card/Elements/ElementCard.ss @@ -1,14 +1,22 @@ -
-
+
+
<% if $Image %> - <% if $ElementLink %><% end_if %> - $Image.Title.ATT - <% if $ElementLink %><% end_if %> + <% if $Position == 'Top' %> + $Image.Title.ATT + <% else %> +
+ $Image.Title.ATT +
+ <% end_if %> <% end_if %> -
- <% if $Title && $ShowTitle %><$TitleTag class="element__title $TitleSizeClass">$Title<% end_if %> - <% if $Content %>
$Content
<% end_if %> - <% if $ElementLink %>

target="_blank" rel="noopener noreferrer"<% end_if %>>$ElementLink.Title

<% end_if %> +
+
+
+ <% if $Title && $ShowTitle %><$TitleTag class="element__title $TitleSizeClass">$Title<% end_if %> + <% if $Content %>
$Content
<% end_if %> + <% if $ElementLink %>

target="_blank" rel="noopener noreferrer"<% end_if %>>$ElementLink.Title

<% end_if %> +
+
-
+
\ No newline at end of file