-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DejaBallard/feat-shortcode
adding shortcode to allow watermarking of images within wysiwyg
- Loading branch information
Showing
4 changed files
with
79 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,5 @@ | ||
<?php | ||
use SilverStripe\View\Parsers\ShortcodeParser; | ||
use Gurucomkz\Watermark\Shortcode; | ||
ShortcodeParser::get('default')->register('watermark', [Shortcode::class, 'Watermark']); | ||
|
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
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,43 @@ | ||
<?php | ||
|
||
namespace Gurucomkz\Watermark; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\HTMLReadonlyField; | ||
/** | ||
* FocusPoint Asset Form Factory extension. | ||
* Extends the CMS detail form to allow focus point selection. | ||
* | ||
* @extends Extension | ||
*/ | ||
class ImageFormFactoryExtension extends Extension | ||
{ | ||
|
||
/** | ||
* Add FocusPoint field for selecting focus. | ||
*/ | ||
public function updateFormFields(FieldList $fields, $controller, $formName, $context) | ||
{ | ||
$image = isset($context['Record']) ? $context['Record'] : null; | ||
if ($image && $image->appCategory() === 'image') { | ||
$wmField = HTMLReadonlyField::create( | ||
'Watermark Shortcode', | ||
)->setValue($this->WatermarkShortCode($image->ID)); | ||
|
||
$titleField = $fields->fieldByName('Editor.Details.Title'); | ||
if ($titleField) { | ||
if ($titleField->isReadonly()) $wmField = $wmField->performReadonlyTransformation(); | ||
$fields->insertAfter( | ||
'Title', | ||
$wmField | ||
); | ||
} | ||
|
||
} | ||
} | ||
|
||
public function WatermarkShortCode($ID){ | ||
return "[watermark id=" . $ID . "]"; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
namespace Gurucomkz\Watermark; | ||
|
||
use PageController; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Assets\Image; | ||
|
||
class Shortcode | ||
{ | ||
|
||
public static function Watermark($arguments, $content = null) | ||
{ | ||
|
||
if (!isset($arguments['file'])) { | ||
return ''; | ||
} | ||
|
||
$image = Image::get()->filter("Name", $arguments['file'])->first(); | ||
if (!isset($image)) { | ||
return ''; | ||
} | ||
if (isset($arguments['position'])) { | ||
return $image->Watermark($arguments['position']); | ||
} else { | ||
return $image->Watermark(); | ||
} | ||
} | ||
} |