Bolt\Twig\Handler\ImageHandler::popup PHP Метод

popup() публичный Метод

example: {{ content.image|popup(320, 240) }} example: {{ popup(content.image, 320, 240) }} example: {{ content.image|popup(width=320, height=240, title="My Image") }}
public popup ( string | array $fileName = null, integer $width = null, integer $height = null, string $crop = null, string $title = null ) : string
$fileName string | array Image file name
$width integer Image width
$height integer Image height
$crop string Crop image string identifier
$title string Display title for image
Результат string HTML output
    public function popup($fileName = null, $width = null, $height = null, $crop = null, $title = null)
    {
        if (empty($fileName)) {
            return '';
        }
        $thumbconf = $this->app['config']->get('general/thumbnails');
        $fullwidth = !empty($thumbconf['default_image'][0]) ? $thumbconf['default_image'][0] : 1000;
        $fullheight = !empty($thumbconf['default_image'][1]) ? $thumbconf['default_image'][1] : 750;
        $thumb = $this->getThumbnail($fileName, $width, $height, $crop);
        $largeThumb = $this->getThumbnail($fileName, $fullwidth, $fullheight, 'r');
        // BC Nightmare… If we're passed a title, use it, if not we might have
        // one in the $fileName array, else use the file name
        $title = $title ?: $thumb->getTitle() ?: sprintf('%s: %s', Trans::__('Image'), $thumb->getFileName());
        $altTitle = $thumb->getAltTitle() ?: $title;
        if ($this->getThumbnailUri($largeThumb)) {
            $output = sprintf('<a href="%s" class="magnific" title="%s"><img src="%s" width="%s" height="%s" alt="%s"></a>', $this->getThumbnailUri($largeThumb), $title, $this->getThumbnailUri($thumb), $thumb->getWidth(), $thumb->getHeight(), $altTitle);
        } else {
            $output = '';
        }
        return $output;
    }

Usage Example

Пример #1
0
 public function testPopupFileNameArrayWithAlt()
 {
     $app = $this->getApp();
     $handler = new ImageHandler($app);
     $result = $handler->popup(['title' => 'Koala', 'alt' => 'Gum Leaves', 'filename' => 'generic-logo.png'], null, null, null, null);
     $this->assertSame('<a href="/thumbs/1000x750r/generic-logo.png" class="magnific" title="Koala"><img src="/thumbs/160x120c/generic-logo.png" width="160" height="120" alt="Gum Leaves"></a>', $result);
 }