diff --git a/app/src/Blocks/FocusPointDemoBlock.php b/app/src/Blocks/FocusPointDemoBlock.php new file mode 100644 index 0000000..4317b55 --- /dev/null +++ b/app/src/Blocks/FocusPointDemoBlock.php @@ -0,0 +1,67 @@ + Image::class, + ]; + + private static $owns = [ + 'Image', + ]; + + private static $table_name = 'FocusPointDemoBlock'; + + private static $singular_name = 'FocusPoint demo'; + + private static $plural_name = 'FocusPoint demo'; + + public function getCMSFields() + { + $description = $this->Image()->exists() + ? sprintf( + 'To customise cropping, you can edit this image', + $this->Image()->CMSEditLink() + ) + : null; + $fields = parent::getCMSFields(); + $fields->addFieldsToTab('Root.Main', [ + $upload = UploadField::create('Image') + ->setDescription($description), + ], 'Content'); + $upload->setAllowedFileCategories('image'); + return $fields; + } + /** + * @return string + */ + public function getSummary(): string + { + return $this->Image()->exists() ? $this->Image()->Filename : 'No image attached'; + } + + /** + * @return array + */ + public function provideBlockSchema(): array + { + $schema = parent::provideBlockSchema(); + $schema['content'] = $this->getSummary(); + + return $schema; + } + + public function getType(): string + { + return _t(__CLASS__ . '.FOCUSPOINTDEMO', 'FocusPoint demo'); + } +} diff --git a/app/templates/SilverStripe/Bambusa/Blocks/FocusPointDemoBlock.ss b/app/templates/SilverStripe/Bambusa/Blocks/FocusPointDemoBlock.ss new file mode 100644 index 0000000..abe8fa1 --- /dev/null +++ b/app/templates/SilverStripe/Bambusa/Blocks/FocusPointDemoBlock.ss @@ -0,0 +1,15 @@ +<% if $Title && $ShowTitle %> +

$Title

+<% end_if %> +
+
$Image.FocusFill(600,300)
+
Fill to 600x300
+
+
+
$Image.FocusCropWidth(500)
+
Cropped to 500 width
+
+
+
$Image.FocusCropHeight(600)
+
Cropped to 600 height
+
\ No newline at end of file