/** * @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>'; }
/** * Returns a map list of all provided module data * * @param Unit $rootUnit * * @return array */ public function getAllModuleData(Unit $rootUnit) { $node = $this->getNodeByUnitId($rootUnit->getId()); $moduleInfoVisitor = new ModuleDataVisitor($this->getRenderContext()); $node->accept($moduleInfoVisitor); return $moduleInfoVisitor->getModuleData(); }
private function getPostValue(Unit $unit) { foreach ($this->formSubmit->getPostValues() as $value) { if ($value->getKey() === $unit->getId()) { return $value->getValue(); } } }
/** * @param Unit $unit * @param string $key * * @return array|null */ public function getUnitValue(Unit $unit, $key) { $key = (string) $key; $path = $this->cachePath . DIRECTORY_SEPARATOR . $unit->getId() . DIRECTORY_SEPARATOR . $this->getFileName($key); if (!is_readable($path)) { return null; } $content = file_get_contents($path); return json_decode($content, true); }
/** * @param $renderApi * @param \Render\Unit $unit * @param Array $tabTitles */ protected function renderTabBar($renderApi, $unit, $tabTitles) { $tabCount = 0; foreach ($tabTitles as $tabTitle) { $tabId = $unit->getId() . '_tab' . $tabCount; $input = new HtmlTagBuilder('input', array('type' => 'radio', 'name' => $unit->getId(), 'id' => $tabId)); if ($tabCount === 0) { $input->set('checked', null); } echo $input->toString(); $label = new HtmlTagBuilder('label', array('for' => $tabId, 'class' => 'tabLabel'), array($tabTitle)); echo $label->toString(); $tabCount++; } }
/** * @param RenderAPI $renderApi * @param Unit $unit * @param ModuleInfo $moduleInfo */ public function renderContent($renderApi, $unit, $moduleInfo) { $formSend = false; $this->http = new \Request(); $form = new \Form(); $honeyPotComponent = new \HoneyPotComponent(); $this->formSubmit = new \FormSubmit(); $postRequest = $this->formSubmit->getPostValues(); $elementProperties = $form->getElementProperties(); $elementProperties->setId("form" . str_replace("-", "", $unit->getId())); $elementProperties->addAttribute('action', $_SERVER['REQUEST_URI'] . '#' . $unit->getId()); $elementProperties->addAttribute('method', 'post'); $elementProperties->addAttribute('enctype', 'multipart/form-data'); $form->add($honeyPotComponent->getHoneyPot()); $form->add($honeyPotComponent->getFormUnitIdentifier($unit->getId())); if ($this->formSubmit->isValid($renderApi, $unit) && count($postRequest) > 0 && $honeyPotComponent->isValidHoneyPot($postRequest) && $this->hasValidFormData($renderApi, $unit)) { $this->formSubmit->setFieldLabelsToFormValueSet($renderApi); try { $this->sentEmail($renderApi, $unit, $postRequest); $formSend = true; } catch (\Exception $e) { $errorText = new \Span(); $errorText->setContent("Unable to send email:<br />" . $e->getMessage()); $errorContainer = new \Container(); $errorContainer->add($errorText); $errorContainer->getElementProperties()->addClass('vf__main_error'); $form->add($errorContainer); } } if ($formSend) { $confirmationText = new \Span(); $confirmationText->setContent(preg_replace('/\\n/', '<br>', $renderApi->getFormValue($unit, 'confirmationText'))); $confirmationContainer = new \Container(); $confirmationContainer->add($confirmationText); $confirmationContainer->getElementProperties()->addClass('confirmationText'); $form->add($confirmationContainer); echo $form->renderElement(); } else { echo $form->renderElementProgressive($renderApi, $unit); } }
/** * @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\HeadAPI $api * @param \Render\Unit $unit * @param \Render\ModuleInfo $moduleInfo * * @return array */ public function provideUnitData($api, $unit, $moduleInfo) { return array('method' => __METHOD__, 'module' => $moduleInfo->getId(), 'unit' => $unit->getId()); }
/** * @return string the module id of the this node */ public function getModuleId() { return $this->unit->getModuleId(); }
/** * @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; }
/** * @param \Render\APIs\APIv1\HeadAPI $api * @param \Render\Unit $unit * @param string $key * * @return mixed */ protected function getUnitContext($api, $unit, $key, $default = null) { $unitId = $unit->getId(); if (!isset($this->unitContext[$unitId])) { return $default; } if (!isset($this->unitContext[$unitId][$key])) { return $default; } return $this->unitContext[$unitId][$key]; }
/** * Triggers the rendering of the given unit with the current renderer * * @param Unit $unit the unit that should be rendered with the current renderer * * @return void */ public function renderUnit(Unit $unit) { $node = $this->getNodeByUnitId($unit->getId()); $node->accept($this->renderingVisitor); }
/** * Returns the module info object for the given unit, null if not found * * @param \Render\Unit $unit * * @return null|\Render\ModuleInfo */ public function getModuleInfo(Unit $unit) { $node = $this->getAbstractRenderNodeById($unit->getId()); if (is_null($node)) { return null; } return $node->getModuleInfo(); }