"; } $columnsCount = count($contentBlock['blocks']); if ($columnsCount === 1) { return $this->renderOneColumn($contentBlock, $columnsData[0]); } return $this->renderMultipleColumns($contentBlock, $columnsData); } private function renderOneColumn($contentBlock, $content) { $template = $this->getOneColumnTemplate( $contentBlock['styles']['block'], isset($contentBlock['image']) ? $contentBlock['image'] : null ); return $template['content_start'] . $content . $template['content_end']; } public function getOneColumnTemplate($styles, $image) { $backgroundCss = $this->getBackgroundCss($styles, $image); $template['content_start'] = ' getBgColorAttribute($styles, $image) . '>
'; $template['content_end'] = '
'; return $template; } private function renderMultipleColumns($contentBlock, $columnsData) { $columnsCount = count($contentBlock['blocks']); $columnsLayout = isset($contentBlock['columnLayout']) ? $contentBlock['columnLayout'] : null; $widths = ColumnsHelper::columnWidth($columnsCount, $columnsLayout); $class = ColumnsHelper::columnClass($columnsCount); $alignment = ColumnsHelper::columnAlignment($columnsCount); $index = 0; $result = $this->getMultipleColumnsContainerStart($class, $contentBlock['styles']['block'], isset($contentBlock['image']) ? $contentBlock['image'] : null); foreach ($columnsData as $content) { $result .= $this->getMultipleColumnsContentStart($widths[$index++], $alignment, $class); $result .= $content; $result .= $this->getMultipleColumnsContentEnd(); } $result .= $this->getMultipleColumnsContainerEnd(); return $result; } private function getMultipleColumnsContainerStart($class, $styles, $image) { return ' getBgColorAttribute($styles, $image) . '>
'; } private function getMultipleColumnsContentEnd() { return '
'; } private function getBackgroundCss($styles, $image) { if ($image !== null && $image['src'] !== null) { $backgroundColor = isset($styles['backgroundColor']) && $styles['backgroundColor'] !== 'transparent' ? $styles['backgroundColor'] : '#ffffff'; $repeat = $image['display'] === 'tile' ? 'repeat' : 'no-repeat'; $size = $image['display'] === 'scale' ? 'cover' : 'contain'; $style = sprintf( 'background: %s url(%s) %s center/%s;background-color: %s;background-image: url(%s);background-repeat: %s;background-position: center;background-size: %s;', $backgroundColor, $image['src'], $repeat, $size, $backgroundColor, $image['src'], $repeat, $size ); return EHelper::escapeHtmlStyleAttr($style); } else { if (!isset($styles['backgroundColor'])) return false; $backgroundColor = $styles['backgroundColor']; return ($backgroundColor !== 'transparent') ? EHelper::escapeHtmlStyleAttr(sprintf('background-color:%s!important;', $backgroundColor)) : false; } } private function getBgColorAttribute($styles, $image) { if ( ($image === null || $image['src'] === null) && isset($styles['backgroundColor']) && $styles['backgroundColor'] !== 'transparent' ) { return 'bgcolor="' . EHelper::escapeHtmlAttr($styles['backgroundColor']) . '"'; } return null; } }