-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate image page, create image block
- Loading branch information
Aaron Carlino
committed
Jul 17, 2019
1 parent
1cd8be1
commit 1a6fa61
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
app/templates/SilverStripe/Bambusa/Blocks/FocusPointDemoBlock.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |