Skip to content

Commit

Permalink
Deprecate image page, create image block
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlino committed Jul 17, 2019
1 parent 1cd8be1 commit 1a6fa61
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
67 changes: 67 additions & 0 deletions app/src/Blocks/FocusPointDemoBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php


namespace SilverStripe\Bambusa\Blocks;

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;

class FocusPointDemoBlock extends BaseElement
{
private static $icon = 'font-icon-image';

private static $has_one = [
'Image' => 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 <a target="_blank" href="%s">edit this image</a>',
$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');
}
}
15 changes: 15 additions & 0 deletions app/templates/SilverStripe/Bambusa/Blocks/FocusPointDemoBlock.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if $Title && $ShowTitle %>
<h2 class="image-block__title">$Title</h2>
<% end_if %>
<figure>
<div>$Image.FocusFill(600,300)</div>
<figcaption>Fill to 600x300</figcaption>
</figure>
<figure>
<div>$Image.FocusCropWidth(500)</div>
<figcaption>Cropped to 500 width</figcaption>
</figure>
<figure>
<div>$Image.FocusCropHeight(600)</div>
<figcaption>Cropped to 600 height</figcaption>
</figure>

0 comments on commit 1a6fa61

Please sign in to comment.