/**
  * 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;
 }
Example #2
0
 /**
  * Get parent to which this file is corresponding.
  *
  * @access   public
  * @return   User
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function getParent()
 {
     return parent::getParent();
 }