Skip to content

Commit

Permalink
Ability to set the defaul page social image to be used when the image…
Browse files Browse the repository at this point in the history
… is missing from the individual page
  • Loading branch information
waiyanheincyberduck committed Apr 3, 2020
1 parent d90b3e9 commit cd53f5a
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 241 deletions.
11 changes: 11 additions & 0 deletions .idea/Silverstripe-SEO.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

222 changes: 222 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions src/Model/Extension/SeoPageControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use Page;
use Exception;
use CyberDuck\SEO\Model\Extension\SeoExtension;
use CyberDuck\SEO\Model\Extension\SeoPageExtension;
use SilverStripe\Assets\Image;
use SilverStripe\Core\Extension;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\SiteConfig\SiteConfig;

/**
* SeoPageControllerExtension
Expand All @@ -25,7 +24,7 @@ class SeoPageControllerExtension extends Extension
*
* @since version 2.0.0
*
* @var DataObject $seo
* @var DataObject $seo
**/
private $seo;

Expand All @@ -49,6 +48,7 @@ public function setSeoObject(DataObject $object)
throw new Exception('setSeoObject must be passed a DataObject with the SeoExtension applied');
}
}

$this->seo = $object;
}

Expand All @@ -64,8 +64,23 @@ public function getPageMetaTags()
$meta = $this->owner->customise([
'SeoPageObject' => ($this->seo ? $this->seo : $this->owner)
])->renderWith('HeadTags')->RAW();

$meta = implode("\n", array_filter(explode("\n", $meta)));
return DBField::create_field('HTMLText', $meta);
}
}

public function getDefaultPageSocialImage()
{
$siteConfig = SiteConfig::get()->first();

if ($siteConfig) {
$image = Image::get()->byID($siteConfig->DefaultPageSocialImageID);

if ($image) {
return $image;
}
}

return null;
}
}
Loading

0 comments on commit cd53f5a

Please sign in to comment.