Heyday\ResponsiveImages\ResponsiveImageExtension
An extension to the Image class to inject methods for responsive image sets.
Image sets are defined in the config layer, e.g:
Heyday\ResponsiveImages\ResponsiveImageExtension:
sets:
MyResponsiveImageSet:
method: Fill
arguments:
"(min-width: 200px)": [200, 100]
"(min-width: 800px)": [200, 400]
"(min-width: 1200px) and (min-device-pixel-ratio: 2.0)": [800, 400]
default_arguments: [200, 400]
This provides $MyImage.MyResponsiveImageSet to the template. For more
documentation on implementation, see the README file.
Synopsis
class ResponsiveImageExtension
extends Extension
{
- // members
- private static array $default_arguments = ;
- private static string $default_method = 'ScaleWidth';
- private static string $default_css_classes = '';
- protected $configSets;
- // methods
- public void __construct()
- public HTMLText __call()
- protected SSViewer createResponsiveSet()
- protected Image getResampledImage()
- protected array|false getConfigForSet()
- protected array getResponsiveSets()
- public array allMethodNames()
Hierarchy
Extends
- SilverStripe\Core\Extension
Members
private
- $default_arguments — array
- $default_css_classes — string
- $default_method — string
protected
- $configSets — array
Methods
protected
- createResponsiveSet() — Requires the necessary JS and sends the required HTML structure to the template for a responsive image set.
- getConfigForSet() — Due to {@link Object::allMethodNames()} requiring methods to be expressed in all lowercase, getting the config for a given method requires a case-insensitive comparison.
- getResampledImage() — Return a resampled image equivalent to $Image.MethodName(...$args) in a template
- getResponsiveSets() — Returns a list of available image sets.
public
- __construct() — {@inheritdoc}
- __call() — A wildcard method for handling responsive sets as template functions, e.g. $MyImage.ResponsiveSet1
- allMethodNames() — Defines all the methods that can be called in this class.