diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e5847b6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) +Copyright © 2020 Wunderman Thompson New Zealand + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 8e70d89..a6f8f78 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SilverStripe Facebook Image -This version supports SilverStripe 3, see the 0.0 branch for a SilverStripe 2.4 compatible version. +This version supports SilverStripe 4, see the 0.1 release for a SilverStripe 3 compatible version and the 0.0 release for a SilverStripe 2.4 compatible version. Provides an Image Field for use when sharing pages on facebook. diff --git a/_config/config.yml b/_config/config.yml index e631e25..ccd30c9 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,7 +1,7 @@ -SiteConfig: +SilverStripe\SiteConfig\SiteConfig: extensions: - - SiteConfigFacebookImageExtension + - WT\FacebookImage\SiteConfigFacebookImageExtension Page: extensions: - - PageFacebookImageExtension \ No newline at end of file + - WT\FacebookImage\PageFacebookImageExtension diff --git a/code/PageFacebookImageExtension.php b/code/PageFacebookImageExtension.php index e72149d..a5e7ecc 100644 --- a/code/PageFacebookImageExtension.php +++ b/code/PageFacebookImageExtension.php @@ -1,14 +1,40 @@ 'Image' - ); + /** + * @var array + */ + private static $has_one = [ + 'FacebookImage' => Image::class, + ]; + + /** + * @var array + */ + private static $owns = [ + 'FacebookImage', + ]; + /** + * @param FieldList $fields + */ public function updateCMSFields(FieldList $fields) { - $fields->addFieldToTab('Root.Facebook', $uf = new UploadField('FacebookImage', 'Facebook image for facebook share')); + $fields->addFieldToTab( + 'Root.Facebook', + $uf = new UploadField('FacebookImage', 'Facebook image for facebook share') + ); + $uf->setFolderName('FacebookImages/'); } @@ -17,7 +43,9 @@ public function updateCMSFields(FieldList $fields) */ public function FacebookImageWithFallback() { - return $this->owner->FacebookImageID ? $this->owner->FacebookImage() : SiteConfig::current_site_config()->FacebookImage(); + return $this->owner->FacebookImageID + ? $this->owner->FacebookImage() + : SiteConfig::current_site_config()->FacebookImage(); } /** @@ -27,4 +55,4 @@ public function FacebookMetaTags() { return Controller::curr()->renderWith('FacebookMetaTags'); } -} \ No newline at end of file +} diff --git a/code/SiteConfigFacebookImageExtension.php b/code/SiteConfigFacebookImageExtension.php index 0f9439e..f7bcaeb 100644 --- a/code/SiteConfigFacebookImageExtension.php +++ b/code/SiteConfigFacebookImageExtension.php @@ -1,15 +1,39 @@ 'Image' - ); + /** + * @var array + */ + private static $has_one = [ + 'FacebookImage' => Image::class, + ]; + /** + * @var array + */ + private static $owns = [ + 'FacebookImage', + ]; + + /** + * @param FieldList $fields + */ public function updateCMSFields(FieldList $fields) { - $fields->addFieldToTab('Root.Facebook', $uf = new UploadField('FacebookImage', 'Default Facebook image for facebook share')); + $fields->addFieldToTab( + 'Root.Facebook', + $uf = new UploadField('FacebookImage', 'Default Facebook image for facebook share'), + ); + $uf->setFolderName('FacebookImages/'); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 699600a..72dae71 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "heyday/silverstripe-facebookimage", "type": "silverstripe-module", "description": "Provides an Image Field for use when sharing pages on facebook", + "type": "silverstripe-vendormodule", "authors": [ { "name": "Glenn Bautista", @@ -9,6 +10,7 @@ } ], "require": { - "composer/installers": "~1.0" + "composer/installers": "~1.0", + "silverstripe/framework": "^4.0.0" } }