/** * Format value. * * @access public * @param ModelCore\FileBroker $oImageBroker * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function format($oImageBroker) { $sOutput = ''; if ($oImageBroker instanceof ModelCore\FileBroker && $oImageBroker->getFile() instanceof \Model\File) { $oAttributes = Helper\Attributes::factory(); $oField = $this->getField(); /* @var $oField \Plethora\View\ViewField */ $oFile = $oImageBroker->getFile(); /* @var $oFile \Model\File */ // set proper ALT if (!empty($this->sImageAltPattern)) { $oModel = $oField->getEntity()->getModel(); $aFields = $oModel->getMetadata()->getFieldNames(); if ($oModel->hasLocales()) { $aFields = array_merge($aFields, $oModel->getLocalesMetadata()->getFieldNames()); } $sAlt = $this->sImageAltPattern; foreach ($aFields as $sField) { if (strpos($sAlt, ':' . $sField) !== FALSE) { $sAlt = str_replace(':' . $sField, $oModel->{$sField}, $sAlt); } if (strpos($sAlt, ':') === FALSE) { break; } } $oAttributes->addToAttribute('alt', $sAlt); } // get image path $sFieldName = $oField->getName(); $oFormField = $oField->getEntity()->getModel()->getConfig()->getField($sFieldName); /* @var $oFormField \Plethora\Form\Field\ImageModel */ $sImagePath = $oFile->getFullPath(); if (empty($sImagePath) && $oFormField->getDefaultImage() === NULL) { return NULL; } elseif (empty($sImagePath) && $oFormField->getDefaultImage() !== NULL) { $sImagePath = $oFormField->getDefaultImage(); } // stylize image if (!empty($this->sImageStyle)) { $sImagePath = ImageStyles::useStyle($this->sImageStyle, $sImagePath); } $oAttributes->addToAttribute('src', Router::getBase() . '/' . $sImagePath); $sOutput = '<img ' . $oAttributes->renderAttributes() . ' />'; // if this image should be linked to it's original-sized equivalent if ($this->bLinkToOriginalSize) { $sImagePathOriginal = '/' . $oFormField->getUploadPath(TRUE) . '/' . $oFile->getNameWithExt(); $oAttributes = Helper\Attributes::factory()->setAttributes($this->aLinkAttributes); $sOutput = Helper\Html::a($sImagePathOriginal, $sOutput, $oAttributes); } } // return final output return $this->sPrefix . $sOutput . $this->sSuffix; }
if ($oFileToShow instanceof \Model\File) { ?> <?php $sWholeFileURL = Router::getBase() . '/' . $oFileToShow->getFullPath(); ?> <?php if (file_exists($oFileToShow->getFullPath())) { ?> <p> <a href="<?php echo $sWholeFileURL; ?> " title=""> <img src="<?php echo Router::getBase() . '/' . ImageStyles::useStyle('admin_preview', $oFileToShow->getFullPath()); ?> " alt=""/> </a> </p> <?php } else { ?> <div class="file_doest_not_exists alert alert-danger"><?php echo __('File does not exists (path: ":path").', ['path' => $sWholeFileURL]); ?> </div> <?php } } ?>