Automattic\WooCommerce\Vendor\Pelago\Emogrifier

CssInliner::copyInlinableCssToStyleAttributeprivateWC 1.0

Copies $cssRule into the style attribute of $node.

Note: This method does not check whether $cssRule matches $node.

Method of the class: CssInliner{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->copyInlinableCssToStyleAttribute( $node, $cssRule ): void;
$node(DOMElement) (required)
.
$cssRule(array) (required)
.

CssInliner::copyInlinableCssToStyleAttribute() code WC 10.5.0

private function copyInlinableCssToStyleAttribute(\DOMElement $node, array $cssRule): void
{
    $declarationsBlock = $cssRule['declarationsBlock'];
    $declarationBlockParser = new DeclarationBlockParser();
    $newStyleDeclarations = $declarationBlockParser->parse($declarationsBlock);
    if ($newStyleDeclarations === []) {
        return;
    }

    // if it has a style attribute, get it, process it, and append (overwrite) new stuff
    if ($node->hasAttribute('style')) {
        // break it up into an associative array
        $oldStyleDeclarations = $declarationBlockParser->parse($node->getAttribute('style'));
    } else {
        $oldStyleDeclarations = [];
    }
    $node->setAttribute(
        'style',
        $this->generateStyleStringFromDeclarationsArrays($oldStyleDeclarations, $newStyleDeclarations)
    );
}