/** * Creates the html code for a single unit and writes it to output buffer. * This is an empty implementation and should be overridden if you want * to output any html code. * * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api * @param \Render\Unit $unit - an object which provides general unit specific * data (e.g. unit id, form values, ... etc.) * @param \Render\ModuleInfo $moduleInfo - reference an object which provides * the general module information (e.g. module id, asset url, manifest * data, ... etc.) */ public function render($renderApi, $unit, $moduleInfo) { if ($moduleInfo->isExtension()) { return; } $tag = new HtmlTagBuilder('div'); $tag->set('id', $unit->getId()); $tag->addClass($moduleInfo->getId()); $tag->addClass('isModule'); $tag->addClass($unit->getHtmlClass()); // call hook $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo); echo $tag->getOpenString(); $this->renderContent($renderApi, $unit, $moduleInfo); echo $tag->getCloseString(); }
/** * Creates the html code for a single unit and writes it to output buffer. * This is an empty implementation and should be overridden if you want * to output any html code. * * @param \Render\APIs\APIv1\RenderAPI $renderApi - reference to the module api * @param \Render\Unit $unit - an object which provides general unit specific * data (e.g. unit id, form values, ... etc.) * @param \Render\ModuleInfo $moduleInfo - reference an object which provides * the general module information (e.g. module id, asset url, manifest * data, ... etc.) */ public function render($renderApi, $unit, $moduleInfo) { if ($moduleInfo->isExtension()) { return; } $tag = new HtmlTagBuilder('div'); $tag->set('id', $unit->getId()); $tag->addClass($moduleInfo->getId()); $tag->addClass('isModule'); $tag->addClass($unit->getHtmlClass()); // add style Set classes $children = $renderApi->getChildren($unit); $styleSetClasses = ''; foreach ($children as $childUnit) { $styleSetClass = $renderApi->getFormValue($childUnit, 'cssStyleSets', false); if ($styleSetClass) { $styleSetClasses .= str_replace(",", " ", $styleSetClass) . " "; } } if ($styleSetClasses != '') { $tag->addClass($styleSetClasses); } // call hook $this->modifyWrapperTag($tag, $renderApi, $unit, $moduleInfo); echo $tag->getOpenString(); $this->renderContent($renderApi, $unit, $moduleInfo); echo $tag->getCloseString(); }
/** * Creates an html tag object that output build the basis for the javascript * responsive image lib * * @param string|\Render\APIs\APIv1\MediaImage $image * The media image object or its id * @param array $imageCfg * The image manipulations; The following keys/values are supported * # 'crop' => array('x' => int, 'y' => int, 'width' => int, 'height' => int) * # 'resize' => array('width' => int, 'height' => int) * # 'quality' => int * @param array attributes * A set of additional tag attributes (key -> attribute name, value -> attribute value) * @return \Rukzuk\Modules\HtmlTagBuilder */ public function getImageTag($image = null, $imageCfg = null, $attributes = null) { // wrapper $wrapper = new HtmlTagBuilder('div', array('class' => 'responsiveImageWrapper')); // image tag $imgTag = new HtmlTagBuilder('img', array('alt' => '')); $imgTag->set($attributes); $imgTag->addClass('imgSize'); // fill height element which helps to keep aspect ratio of image (using %-padding technique) $fillHeight = new HtmlTagBuilder('div', array('class' => 'fillHeight')); try { if (is_string($image)) { // get the image object if a image id was given $image = $this->api->getMediaItem($image)->getImage(); } } catch (Exception $e) { } // we have a image (object) if (is_object($image)) { // height in percent of the width (used for padding trick) $origWidth = $image->getOriginalWidth(); $origHeight = $image->getOriginalHeight(); $origHeightRatio = $origHeight / $origWidth * 100; // create the image urls for each of the pre-defined and most common device resolutions $imgUrls = $this->getResponsiveImageUrls($image->getMediaItem(), $imageCfg); // provide big, not cropped image, // used in image cropper (panzoom) and for rz_lightbox try { $image->resetOperations(); $image = $image->resizeScale(ResponsiveImageBuilder::$maxResponsiveImageResolution); $imgTag->set('data-cms-origsrc', $image->getUrl()); } catch (Exception $e) { // do nothing } // indicate that we have an actual image $wrapper->addClass('hasImage'); // data for js image replacement code (lazy sizes) // build src set $srcSet = array(); foreach ($imgUrls as $w => $u) { $srcSet[] = $u . ' ' . $w . 'w'; } $imgTag->set(array('data-sizes' => 'auto', 'data-srcset' => implode(', ', $srcSet))); $imgTag->addClass('lazyload'); $imgTag->addClass('responsiveImage'); // set default image (smallest resolution LQIP for fast responses) $image->resetOperations(); $preloadSrc = $this->getResponsiveImageUrl($image, $imageCfg, ResponsiveImageBuilder::$previewResponsiveImageResolution); $imgTag->set('src', $preloadSrc); // set fill height value $imgHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%'); // use original aspect ratio as height if 0% $fillHeightPaddingBottom = $imgHeight == '0%' ? sprintf('%F', $origHeightRatio) . '%' : $imgHeight; } else { // show a blank image $imgTag->addClass('blankImgPlaceholder')->set('src', $this->getPlaceholderUrl()); // set fill height value - use 50% if it is 0% (original image) because blank image has no size (it is a background) $blankHeight = $this->api->getFormValue($this->unit, 'imgHeight', '0%'); // use 50% as height, because we don't have a original aspect ratio $fillHeightPaddingBottom = $blankHeight == '0%' ? '50%' : $blankHeight; } $fillHeight->set('style', 'padding-bottom: ' . $fillHeightPaddingBottom . ';'); $wrapper->append($imgTag); $wrapper->append($fillHeight); return $wrapper; }
/** * @param $text * @param \Render\APIs\APIv1\Page $productPage * @param string $cartUrl * @param bool $preventSubmit * @param Translator $i18n * * @return HtmlTagBuilder */ private function displayCartButton($text, $productPage, $cartUrl, $preventSubmit, $i18n) { // form $form = new HtmlTagBuilder('form', array('action' => $cartUrl, 'method' => 'POST'), array(new HtmlTagBuilder('input', array('type' => 'hidden', 'name' => 'productPageId', 'value' => $productPage->getPageId())), new HtmlTagBuilder('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'addToCart')))); // variants select if ($this->isVariantsEnabled($productPage)) { $form->append($this->buildVariantSelect(explode("\n", $this->getPageAttribute($productPage, 'variants')))); } // cart button $cartBtn = new HtmlTagBuilder('button', array('type' => 'submit', 'class' => 'pd-addToCartButton'), array($text)); if ($preventSubmit) { $cartBtn->addClass('pd-preventSubmit'); $cartBtn->set('onClick', 'alert("' . $i18n->translate('msg.editTplModeError') . '"); return false;'); } $form->append($cartBtn); return $form; }