From 4adcea7361f01e257e08e2928bc90a848541c94f Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 13 Aug 2024 21:57:05 -0500 Subject: [PATCH 1/2] FEATURE Image position options --- src/Element/ElementCard.php | 21 ++++++++++---- .../Elements/Card/Elements/ElementCard.ss | 28 ++++++++++++------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Element/ElementCard.php b/src/Element/ElementCard.php index 979ef5e..a378c2f 100644 --- a/src/Element/ElementCard.php +++ b/src/Element/ElementCard.php @@ -51,7 +51,7 @@ class ElementCard extends BaseElement * @var string * @config */ - private static string $icon = 'font-icon-block-content'; + private static string $icon = 'font-icon-block-content'; /** * @var array|string[] @@ -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; } @@ -100,15 +104,20 @@ public function fieldLabels($includerelations = true) public function getCMSFields(): FieldList { $this->beforeUpdateCMSFields(function (FieldList $fields) { + // @phpstan-ignore-next-line + $fields->dataFieldByName('Content') + ->setRows(8); + // @phpstan-ignore-next-line $fields->dataFieldByName('Image') ->setFolderName('Uploads/Elements/Card'); + $fields->insertBefore('Position', $fields->dataFieldByName('Image')); - $fields->insertBefore('Content', $fields->dataFieldByName('Image')); - - // @phpstan-ignore-next-line - $fields->dataFieldByName('Content') - ->setRows(5); + $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 From 5696e4656abf969e6d148485177af6000d566e81 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Tue, 13 Aug 2024 22:04:12 -0500 Subject: [PATCH 2/2] phpcs --- src/Element/ElementCard.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Element/ElementCard.php b/src/Element/ElementCard.php index a378c2f..e53580e 100644 --- a/src/Element/ElementCard.php +++ b/src/Element/ElementCard.php @@ -51,7 +51,7 @@ class ElementCard extends BaseElement * @var string * @config */ - private static string $icon = 'font-icon-block-content'; + private static string $icon = 'font-icon-block-content'; /** * @var array|string[] @@ -115,8 +115,9 @@ public function getCMSFields(): FieldList $fields->dataFieldByName('Position') ->setDescription(_t( - __CLASS__ . 'PositionDescription', - 'Position of the image in relation to the content. Image will display on top at smaller breakpoints.' + __CLASS__ . 'PositionDescription', + 'Position of the image in relation to the content. + Image will display on top at smaller breakpoints.' )); $fields->replaceField(