1*37748cd8SNickeau<?php 2*37748cd8SNickeau 3*37748cd8SNickeau 4*37748cd8SNickeaunamespace ComboStrap; 5*37748cd8SNickeau 6*37748cd8SNickeau 7*37748cd8SNickeauclass Spacing 8*37748cd8SNickeau{ 9*37748cd8SNickeau const SPACING_ATTRIBUTE = "spacing"; 10*37748cd8SNickeau 11*37748cd8SNickeau /** 12*37748cd8SNickeau * Process the attributes that have an impact on the class 13*37748cd8SNickeau * @param TagAttributes $attributes 14*37748cd8SNickeau */ 15*37748cd8SNickeau public static function processSpacingAttributes(&$attributes) 16*37748cd8SNickeau { 17*37748cd8SNickeau 18*37748cd8SNickeau // Spacing is just a class 19*37748cd8SNickeau $spacing = self::SPACING_ATTRIBUTE; 20*37748cd8SNickeau if ($attributes->hasComponentAttribute($spacing)) { 21*37748cd8SNickeau 22*37748cd8SNickeau $spacingValue = $attributes->getValueAndRemove($spacing); 23*37748cd8SNickeau 24*37748cd8SNickeau /** 25*37748cd8SNickeau * Applying a padding on svg is not really recommended 26*37748cd8SNickeau * because it makes the icon invisble 27*37748cd8SNickeau */ 28*37748cd8SNickeau $logicalTag = $attributes->getLogicalTag(); 29*37748cd8SNickeau if ($logicalTag == SvgImageLink::CANONICAL) { 30*37748cd8SNickeau if (StringUtility::startWiths($spacingValue, "p")) { 31*37748cd8SNickeau LogUtility::msg("We didn't apply the padding value ($spacingValue) on your svg or icon because it will make the icon invisible. Apply a margin or apply the spacing to the container component.", LogUtility::LVL_MSG_WARNING, SvgImageLink::CANONICAL); 32*37748cd8SNickeau return; 33*37748cd8SNickeau } 34*37748cd8SNickeau } 35*37748cd8SNickeau if ($logicalTag == \syntax_plugin_combo_cell::TAG) { 36*37748cd8SNickeau if (StringUtility::startWiths($spacingValue, "m")) { 37*37748cd8SNickeau $expectedValue = "p" . substr($spacingValue, 1); 38*37748cd8SNickeau LogUtility::msg("We didn't apply the margin value ($spacingValue) on your column because it will make the last column in the grid to go to the line. Apply the following padding instead ($expectedValue)", LogUtility::LVL_MSG_WARNING, \syntax_plugin_combo_row::CANONICAL); 39*37748cd8SNickeau $spacingValue = $expectedValue; 40*37748cd8SNickeau } 41*37748cd8SNickeau } 42*37748cd8SNickeau 43*37748cd8SNickeau $spacingNames = preg_split("/\s/", $spacingValue); 44*37748cd8SNickeau $bootstrapVersion = Bootstrap::getBootStrapMajorVersion(); 45*37748cd8SNickeau foreach ($spacingNames as $spacingClass) { 46*37748cd8SNickeau if ($bootstrapVersion == Bootstrap::BootStrapFiveMajorVersion) { 47*37748cd8SNickeau 48*37748cd8SNickeau // The sides r and l has been renamed to e and s 49*37748cd8SNickeau // https://getbootstrap.com/docs/5.0/migration/#utilities-2 50*37748cd8SNickeau // 51*37748cd8SNickeau 52*37748cd8SNickeau // https://getbootstrap.com/docs/5.0/utilities/spacing/ 53*37748cd8SNickeau // By default, we consider tha there is no size and breakpoint 54*37748cd8SNickeau $sizeAndBreakPoint = ""; 55*37748cd8SNickeau $propertyAndSide = $spacingClass; 56*37748cd8SNickeau 57*37748cd8SNickeau $minusCharacter = "-"; 58*37748cd8SNickeau $minusLocation = strpos($spacingClass, $minusCharacter); 59*37748cd8SNickeau if ($minusLocation !== false) { 60*37748cd8SNickeau // There is no size or break point 61*37748cd8SNickeau $sizeAndBreakPoint = substr($spacingClass, $minusLocation + 1); 62*37748cd8SNickeau $propertyAndSide = substr($spacingClass, 0, $minusLocation); 63*37748cd8SNickeau } 64*37748cd8SNickeau $propertyAndSide = str_replace("r", "e", $propertyAndSide); 65*37748cd8SNickeau $propertyAndSide = str_replace("l", "s", $propertyAndSide); 66*37748cd8SNickeau if ($sizeAndBreakPoint === "") { 67*37748cd8SNickeau $spacingClass = $propertyAndSide; 68*37748cd8SNickeau } else { 69*37748cd8SNickeau $spacingClass = $propertyAndSide . $minusCharacter . $sizeAndBreakPoint; 70*37748cd8SNickeau } 71*37748cd8SNickeau 72*37748cd8SNickeau } 73*37748cd8SNickeau $attributes->addClassName($spacingClass); 74*37748cd8SNickeau } 75*37748cd8SNickeau } 76*37748cd8SNickeau 77*37748cd8SNickeau } 78*37748cd8SNickeau} 79