Source of file SeoPageControllerExtension.php
Size: 2,237 Bytes - Last Modified: 2021-12-24T06:43:33+00:00
/var/www/docs.ssmods.com/process/src/src/Model/Extension/SeoPageControllerExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | <?php namespace CyberDuck\SEO\Model\Extension; use Page; use Exception; use SilverStripe\Assets\Image; use SilverStripe\Core\Extension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\SiteConfig\SiteConfig; /** * SeoPageControllerExtension * * @package silverstripe-seo * @license MIT License https://github.com/cyber-duck/silverstripe-seo/blob/master/LICENSE * @author <andrewm@cyber-duck.co.uk> */ class SeoPageControllerExtension extends Extension { /** * A DataObject instance to pull the current page SEO properties from * * @since version 2.0.0 * * @var DataObject $seo **/ private $seo; /** * Set the model to use for the current page Meta * * @since version 2.0.0 * * @param DataObject $object * * @return void **/ public function setSeoObject(DataObject $object) { if($object instanceof Page || is_subclass_of($object, Page::class)) { if(!$object->hasExtension(SeoPageExtension::class)) { throw new Exception('setSeoObject must be passed a Page with the SeoPageExtension applied'); } } else { if(!$object->hasExtension(SeoExtension::class)) { throw new Exception('setSeoObject must be passed a DataObject with the SeoExtension applied'); } } $this->seo = $object; } /** * Return the head tags to use for the current page * * @since version 2.0.0 * * @return ViewableData **/ 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; } } |