/** * @param \Render\APIs\APIv1\RenderAPI $renderApi * @param \Render\Unit $unit * @param \Render\ModuleInfo $moduleInfo */ public function render($renderApi, $unit, $moduleInfo) { $classes = array($moduleInfo->getId(), 'isModule', 'isColumnBox', htmlspecialchars($unit->getHtmlClass(), ENT_QUOTES, 'UTF-8')); // show add module button in page mode if this is a ghost container if ($renderApi->isEditMode() && $renderApi->isPage() && $unit->isGhostContainer()) { $classes[] = 'showAddModuleButton'; } // Dimensions, Grid, Responsive-Settings $i = 0; $resolutions = $renderApi->getResolutions(); $childWidth = $this->getResponsiveValue($unit, 'cssChildWidth', $renderApi); $maxCols = 0; $cols = array(); foreach ($childWidth as $widths) { $col = count(explode(' ', trim($widths['value']))); $cols[] = $col; if ($col > $maxCols) { $maxCols = $col; } } $allItems = $renderApi->getChildren($unit); $renderItems = array(); // normal units $nonRenderItems = array(); // extension units foreach ($allItems as $item) { if ($renderApi->getModuleInfo($item)->isExtension()) { // assume that extension modules (i.e. styles) render no html output $nonRenderItems[] = $item; } else { $renderItems[] = $item; } } $counter = max($maxCols, count($renderItems)); $unitId = $unit->getId(); $classesStr = implode(' ', $classes); echo "<div id='{$unitId}' class='{$classesStr}'><div class='isColumnBoxTable wkFixTableLayout'>"; for ($i = 0; $i < $counter; $i++) { if (array_key_exists($i, $renderItems)) { // cell has an item echo '<div class="isColumnBoxCell">'; $renderApi->renderUnit($renderItems[$i]); echo '</div>'; if ($i === count($renderItems) - 1) { echo '<div class="boxSpacer boxSpacerLast"></div>'; } else { echo '<div class="boxSpacer"></div>'; } } else { // empty cell echo '<div class="boxPreview isColumnBoxCell">'; if ($renderApi->isEditMode()) { echo '<div class="RUKZUKemptyBox"></div>'; } echo '</div>'; echo '<div class="boxSpacer boxPreviewSpacer"></div>'; } } echo '</div></div>'; }
/** * @test * @group rendering * @group small * @group dev */ public function test_createNewInstance() { // ARRANGE $expectedId = 'this is the unit id'; $expectedModuleId = 'this is the unit module id'; $expectedName = 'this is the unit name'; $expectedFormValues = array('this is one unit form value'); $expectedGhostContainer = true; $expectedTemplateUnitId = 'this is the unit template id'; $expectedHtmlClass = 'this is the html class'; // ACT $actualUnit = new Unit($expectedId, $expectedModuleId, $expectedName, $expectedFormValues, $expectedGhostContainer, $expectedTemplateUnitId, $expectedHtmlClass); // ASSERT $this->assertEquals($expectedId, $actualUnit->getId()); $this->assertEquals($expectedModuleId, $actualUnit->getModuleId()); $this->assertEquals($expectedName, $actualUnit->getName()); $this->assertEquals($expectedFormValues, $actualUnit->getFormValues()); $this->assertEquals($expectedGhostContainer, $actualUnit->isGhostContainer()); $this->assertEquals($expectedTemplateUnitId, $actualUnit->getTemplateUnitId()); $this->assertEquals($expectedHtmlClass, $actualUnit->getHtmlClass()); }
/** * @param \Render\APIs\APIv1\RenderAPI $api * @param \Render\Unit $unit */ protected function insertMissingInputHint($api, $unit) { // only available in edit mode if (!$api->isEditMode()) { return; } $isPage = $api->isPage(); $isGhostContainer = $unit->isGhostContainer(); $isEmpty = true; // check if this module contains any other module which is not a extension module // if we have children, search for non extension modules $children = $api->getChildren($unit); foreach ($children as $nextUnit) { if (!$api->getModuleInfo($nextUnit)->isExtension()) { $isEmpty = false; break; } } $html = ''; // module has no children and we are not in page mode if ($isEmpty && !$isPage) { $html = '<div class="RUKZUKemptyBox"></div>'; } else { if ($isPage && $isGhostContainer) { $id = $unit->getId(); $i18n = new Translator($api, $api->getModuleInfo($unit)); $title = $i18n->translate('button.missingInputHintTitle', 'Click to insert module'); $html .= '<div class="' . ($isEmpty ? ' RUKZUKemptyBox' : 'RUKZUKaddModuleBox') . '">'; $html .= ' <div class="RUKZUKmissingInputHint">'; $html .= ' <div>'; $html .= ' <button class="add" onclick="javascript:CMS.openInsertWindow(\'' . $id . '\', 0);" title="' . $title . '"></button>'; $html .= ' </div>'; $html .= ' </div>'; $html .= '</div>'; } } echo $html; }