Source of file FeaturedImageShortcode.php
Size: 3,703 Bytes - Last Modified: 2021-12-23T10:04:37+00:00
/var/www/docs.ssmods.com/process/src/src/Shortcodes/FeaturedImageShortcode.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | <?php namespace Restruct\Silverstripe\AdminTweaks\Shortcodes { use SilverStripe\Assets\Image; use SilverStripe\Control\Controller; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; use SilverStripe\ORM\DataObject; use SilverStripe\View\SSViewer; use SilverStripe\View\ViewableData; class FeaturedImageShortcode extends ViewableData { /** * @config string the actual shortcode used/inserted into the HTML editor */ private static $shortcode = 'featuredimage'; /** * @config string alternative parse_shortcode callback function (if not parse_shortcode) */ // private static $shortcode_callback = 'parse_shortcode'; /** * @return string the 'label' to use for this shortcode in the shortcodable dropdown */ public function getShortcodeLabel() { return $this->singular_name(); } /** * @return string fallback for shortcode type/label (may be different from shortcode_label on eg DataObjects) */ public function singular_name() { return _t('MED.FeaturedImageShortcode', 'Pagina afbeelding van huidige pagina invoegen'); } /** * @return FieldList fields to use as attributes when inserting this item as shortcode */ public static function getShortcodeFields() { return FieldList::create( TextField::create('title', 'Image title')->setDescription('Optional, shown when hovering image'), DropdownField::create('size', 'Image size', ['md' => 'Medium width', 'full' => 'Full width']), CheckboxField::create('webm', 'Provide WEBM version of image for supporting browsers (optional)') ); } /** * Callback function to parse this item's shortcode into HTML * * @param $arguments * @param $content * @param $parser * @param $shortcode * @return string */ public static function parse_shortcode($attrs, $content=null, $parser=null, $shortcode, $info=null) { $ctrl = Controller::curr(); $size = isset($attrs['size']) && $attrs['size']=='full' ? '1000, 600' : '640, 480'; /** @var Image $featImg */ if ( $featImg = $ctrl->FeaturedImage() ) { // return '<div class="image">' . $featImg->Fill(640, 500)->forTemplate() . '</div>'; return $featImg->renderWith(SSViewer::fromString('<div class="image"><% if $CroppedFill('.$size.') %>$CroppedFill('.$size.')<% else %>$Fill('.$size.')<% end_if %></div>')); } } // /** // * Return a link to an image to be displayed as a placeholder in the editor // * // * @param array $attributes the list of attributes of the shortcode // * @return String // **/ // public function getShortcodePlaceHolder($attributes) // { //// $text = $this->Title; //// if (isset($attributes['Style'])) { //// $text .= ' (' . $attributes['Style'] . ')'; //// } // // $params = array( // 'txt' => 'Placeholder', // 'w' => '400', // 'h' => '200', // 'txtsize' => '27', // 'bg' => '000000', // 'txtclr' => 'cccccc' // ); // // return 'https://placeholdit.imgix.net/~text?' . http_build_query($params); // } } } |