Skip to content

Commit

Permalink
Added ability to link images in FeatureComponent.
Browse files Browse the repository at this point in the history
  • Loading branch information
colintucker committed May 22, 2018
1 parent 84a073e commit 3a5d6db
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/Components/FeatureComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class FeatureComponent extends BaseComponent
'ButtonLabel' => 'Varchar(128)',
'LinkHeading' => 'Boolean',
'LinkFeature' => 'Boolean',
'LinkImage' => 'Boolean',
'ShowIcon' => 'Boolean',
'ShowImage' => 'Boolean',
'ShowHeader' => 'Boolean',
Expand Down Expand Up @@ -135,6 +136,7 @@ class FeatureComponent extends BaseComponent
private static $defaults = [
'LinkFeature' => 0,
'LinkHeading' => 1,
'LinkImage' => 0,
'ShowIcon' => 1,
'ShowImage' => 1,
'ShowHeader' => 1,
Expand All @@ -149,7 +151,8 @@ class FeatureComponent extends BaseComponent
* @config
*/
private static $casting = [
'SummaryText' => 'HTMLFragment'
'SummaryText' => 'HTMLFragment',
'ImageLinkAttributesHTML' => 'HTMLFragment'
];

/**
Expand Down Expand Up @@ -315,6 +318,10 @@ public function getCMSFields()
'LinkFeature',
$this->fieldLabel('LinkFeature')
),
CheckboxField::create(
'LinkImage',
$this->fieldLabel('LinkImage')
),
TextField::create(
'ButtonLabel',
$this->fieldLabel('ButtonLabel')
Expand Down Expand Up @@ -352,6 +359,7 @@ public function fieldLabels($includerelations = true)
$labels['ShowFooter'] = _t(__CLASS__ . '.SHOWFOOTER', 'Show footer');
$labels['LinkHeading'] = _t(__CLASS__ . '.LINKHEADING', 'Link heading');
$labels['LinkFeature'] = _t(__CLASS__ . '.LINKFEATURE', 'Link feature');
$labels['LinkImage'] = _t(__CLASS__ . '.LINKIMAGE', 'Link image');
$labels['ButtonLabel'] = _t(__CLASS__ . '.BUTTONLABEL', 'Button label');
$labels['Heading'] = _t(__CLASS__ . '.HEADING', 'Heading');
$labels['SubHeading'] = _t(__CLASS__ . '.SUBHEADING', 'Sub-heading');
Expand Down Expand Up @@ -489,6 +497,33 @@ public function getLinkClassNames()
return $classes;
}

/**
* Answers an array of attributes for the image link element.
*
* @return array
*/
public function getImageLinkAttributes()
{
$attributes = [
'href' => $this->getLink(),
'class' => 'image'
];

$this->extend('updateImageLinkAttributes', $attributes);

return $attributes;
}

/**
* Answers a string of attributes for the image link element.
*
* @return string
*/
public function getImageLinkAttributesHTML()
{
return $this->getAttributesHTML($this->getImageLinkAttributes());
}

/**
* Answers the heading tag for the receiver.
*
Expand Down Expand Up @@ -623,6 +658,16 @@ public function getHeadingLinked()
return ($this->LinkHeading && $this->hasLink() && !$this->LinkFeature);
}

/**
* Answers true if the image is to be linked.
*
* @return boolean
*/
public function getImageLinked()
{
return ($this->LinkImage && $this->hasLink() && !$this->LinkFeature);
}

/**
* Answers true if the summary is to be shown in the template.
*
Expand Down Expand Up @@ -651,7 +696,7 @@ public function getFooterShown()
public function getSummaryText()
{
if ($this->Summary) {
return $this->Summary;
return $this->dbObject('Summary');
}

if ($this->hasLinkPage()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% if $ImageShown %>
<div class="image">
<% if $ImageLinked %><a $ImageLinkAttributesHTML><% end_if %>
<img src="$ImageResized.URL" class="$ImageClass" title="$Self.Title" alt="$Self.Title">
<% if $ImageLinked %></a><% end_if %>
</div>
<% end_if %>

0 comments on commit 3a5d6db

Please sign in to comment.