Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet
DeclarationBlock::expandBackgroundShorthand
Deprecated since since 8.7.0, will be removed without substitution in version 9.0 in #511. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.
Converts shorthand background declarations (e.g. background: url("chess.png") gray 50% repeat fixed;) into their constituent parts.
Method of the class: DeclarationBlock{}
No Hooks.
Returns
null. Nothing (null).
Usage
$DeclarationBlock = new DeclarationBlock(); $DeclarationBlock->expandBackgroundShorthand();
Notes
Changelog
| Deprecated | Since 8.7.0 | , will be removed without substitution in version 9.0 in #511 |
DeclarationBlock::expandBackgroundShorthand() DeclarationBlock::expandBackgroundShorthand code WC 10.5.0
public function expandBackgroundShorthand()
{
$aRules = $this->getRulesAssoc();
if (!isset($aRules['background'])) {
return;
}
$oRule = $aRules['background'];
$aBgProperties = [
'background-color' => ['transparent'],
'background-image' => ['none'],
'background-repeat' => ['repeat'],
'background-attachment' => ['scroll'],
'background-position' => [
new Size(0, '%', false, $this->getLineNo()),
new Size(0, '%', false, $this->getLineNo()),
],
];
$mRuleValue = $oRule->getValue();
$aValues = [];
if (!$mRuleValue instanceof RuleValueList) {
$aValues[] = $mRuleValue;
} else {
$aValues = $mRuleValue->getListComponents();
}
if (count($aValues) == 1 && $aValues[0] == 'inherit') {
foreach ($aBgProperties as $sProperty => $mValue) {
$oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
$oNewRule->addValue('inherit');
$oNewRule->setIsImportant($oRule->getIsImportant());
$this->addRule($oNewRule);
}
$this->removeRule('background');
return;
}
$iNumBgPos = 0;
foreach ($aValues as $mValue) {
if (!$mValue instanceof Value) {
$mValue = mb_strtolower($mValue);
}
if ($mValue instanceof URL) {
$aBgProperties['background-image'] = $mValue;
} elseif ($mValue instanceof Color) {
$aBgProperties['background-color'] = $mValue;
} elseif (in_array($mValue, ['scroll', 'fixed'])) {
$aBgProperties['background-attachment'] = $mValue;
} elseif (in_array($mValue, ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'])) {
$aBgProperties['background-repeat'] = $mValue;
} elseif (
in_array($mValue, ['left', 'center', 'right', 'top', 'bottom'])
|| $mValue instanceof Size
) {
if ($iNumBgPos == 0) {
$aBgProperties['background-position'][0] = $mValue;
$aBgProperties['background-position'][1] = 'center';
} else {
$aBgProperties['background-position'][$iNumBgPos] = $mValue;
}
$iNumBgPos++;
}
}
foreach ($aBgProperties as $sProperty => $mValue) {
$oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
$oNewRule->setIsImportant($oRule->getIsImportant());
$oNewRule->addValue($mValue);
$this->addRule($oNewRule);
}
$this->removeRule('background');
}