Contao\Controller::generateMargin PHP Method

generateMargin() public static method

Compile the margin format definition based on an array of values
public static generateMargin ( array $arrValues, string $strType = 'margin' ) : string
$arrValues array An array of four values and a unit
$strType string Either "margin" or "padding"
return string The CSS markup
    public static function generateMargin($arrValues, $strType = 'margin')
    {
        // Initialize an empty array (see #5217)
        if (!is_array($arrValues)) {
            $arrValues = array('top' => '', 'right' => '', 'bottom' => '', 'left' => '', 'unit' => '');
        }
        $top = $arrValues['top'];
        $right = $arrValues['right'];
        $bottom = $arrValues['bottom'];
        $left = $arrValues['left'];
        // Try to shorten the definition
        if ($top != '' && $right != '' && $bottom != '' && $left != '') {
            if ($top == $right && $top == $bottom && $top == $left) {
                return $strType . ':' . $top . $arrValues['unit'] . ';';
            } elseif ($top == $bottom && $right == $left) {
                return $strType . ':' . $top . $arrValues['unit'] . ' ' . $left . $arrValues['unit'] . ';';
            } elseif ($top != $bottom && $right == $left) {
                return $strType . ':' . $top . $arrValues['unit'] . ' ' . $right . $arrValues['unit'] . ' ' . $bottom . $arrValues['unit'] . ';';
            } else {
                return $strType . ':' . $top . $arrValues['unit'] . ' ' . $right . $arrValues['unit'] . ' ' . $bottom . $arrValues['unit'] . ' ' . $left . $arrValues['unit'] . ';';
            }
        }
        $return = array();
        $arrDir = array('top' => $top, 'right' => $right, 'bottom' => $bottom, 'left' => $left);
        foreach ($arrDir as $k => $v) {
            if ($v != '') {
                $return[] = $strType . '-' . $k . ':' . $v . $arrValues['unit'] . ';';
            }
        }
        return implode($return);
    }