Heyday\ResponsiveImages\ResponsiveImageExtension::createResponsiveSet PHP Method

createResponsiveSet() protected method

Requires the necessary JS and sends the required HTML structure to the template for a responsive image set.
protected createResponsiveSet ( array $config, array $defaultArgs, string $set ) : SSViewer
$config array The configuration of the responsive image set
$defaultArgs array The arguments passed to the responsive image method call, e.g. $MyImage.ResponsiveSet(800x600)
$set string The method, or responsive image set, to generate
return SSViewer
    protected function createResponsiveSet($config, $defaultArgs, $set)
    {
        Requirements::javascript(RESPONSIVE_IMAGES_DIR . '/javascript/picturefill/picturefill.min.js');
        if (!isset($config['arguments']) || !is_array($config['arguments'])) {
            throw new Exception("Responsive set {$set} does not have any arguments defined in its config.");
        }
        if (empty($defaultArgs)) {
            if (isset($config['default_arguments'])) {
                $defaultArgs = $config['default_arguments'];
            } else {
                $defaultArgs = Config::inst()->get(__CLASS__, 'default_arguments');
            }
        }
        if (isset($config['method'])) {
            $methodName = $config['method'];
        } else {
            $methodName = Config::inst()->get(__CLASS__, 'default_method');
        }
        $sizes = ArrayList::create();
        foreach ($config['arguments'] as $query => $args) {
            if (is_numeric($query) || !$query) {
                throw new Exception("Responsive set {$set} has an empty media query. Please check your config format");
            }
            if (!is_array($args) || empty($args)) {
                throw new Exception("Responsive set {$set} doesn't have any arguments provided for the query: {$query}");
            }
            array_unshift($args, $methodName);
            $image = call_user_func_array(array($this->owner, 'getFormattedImage'), $args);
            $sizes->push(ArrayData::create(array('Image' => $image, 'Query' => $query)));
        }
        // The first argument may be an image method such as 'CroppedImage'
        if (!isset($defaultArgs[0]) || !$this->owner->hasMethod($defaultArgs[0])) {
            array_unshift($defaultArgs, $methodName);
        }
        $image = call_user_func_array(array($this->owner, 'getFormattedImage'), $defaultArgs);
        return $this->owner->customise(array('Sizes' => $sizes, 'DefaultImage' => $image))->renderWith('ResponsiveImageSet');
    }