Themosis\Asset\Asset::addAttributes PHP Method

addAttributes() public method

Add attributes to the asset opening tag.
public addAttributes ( array $atts ) : Asset
$atts array The asset attributes to add.
return Asset
    public function addAttributes(array $atts)
    {
        $html = $this->html;
        $key = $this->key;
        $replace = function ($tag, $atts, $append) use($html) {
            if (false !== ($pos = strrpos($tag, $append))) {
                $tag = substr_replace($tag, $html->attributes($atts), $pos) . ' ' . trim($append);
            }
            return $tag;
        };
        if ('script' === $this->type) {
            $append = '></script>';
            $this->filter->add('script_loader_tag', function ($tag, $handle) use($atts, $append, $replace, $key) {
                // Check we're only filtering the current asset and not all.
                if ($key === $handle) {
                    return $replace($tag, $atts, $append);
                }
                return $tag;
            });
        }
        if ('style' === $this->type) {
            $append = ' />';
            $this->filter->add('style_loader_tag', function ($tag, $handle) use($atts, $append, $replace, $key) {
                // Check we're only filtering the current asset and not all.
                if ($key === $handle) {
                    return $replace($tag, $atts, $append);
                }
                return $tag;
            }, 4);
        }
        return $this;
    }