Skip to content

Commit

Permalink
Improve image and add alt and caption
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidpeywasti committed Feb 22, 2017
1 parent 13289e7 commit 10e61df
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
41 changes: 32 additions & 9 deletions modules/ModuleLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,44 @@ protected function parseLink($objLink, $strClass='', $intCount=0)

$objTemplate->setData($objLink->row());

$strImage = '';
$objImage = \FilesModel::findByPk($objLink->singleSRC);
$objTemplate->addImage = false;

$size = deserialize($this->imgSize);

// Add image
if ($objImage !== null)
// Add an image
if ($objLink->singleSRC != '')
{
$strImage = \Image::getHtml(\Image::get($objImage->path, $size[0],$size[1],$size[2]));
}
$objModel = \FilesModel::findByUuid($objLink->singleSRC);

if ($objModel === null)
{
if (!\Validator::isUuid($objLink->singleSRC))
{
$objTemplate->text = '<p class="error">'.$GLOBALS['TL_LANG']['ERR']['version2format'].'</p>';
}
}
elseif (is_file(TL_ROOT . '/' . $objModel->path))
{
// Do not override the field now that we have a model registry (see #6303)
$arrLink = $objLink->row();

// Override the default image size
if ($this->imgSize != '')
{
$size = deserialize($this->imgSize);

if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2]))
{
$arrLink['size'] = $this->imgSize;
}
}

$arrLink['singleSRC'] = $objModel->path;
$this->addImageToTemplate($objTemplate, $arrLink);
}
}

$objTemplate->class = $strClass;
$objTemplate->hrefclass = $objLink->class;
$objTemplate->linkTitle = $objLink->linkTitle ? $objLink->linkTitle : $objLink->title;
$objTemplate->image = $strImage;

return $objTemplate->parse();

Expand Down
14 changes: 12 additions & 2 deletions templates/links/links_image.html5
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

<li class="link<?= $this->class; ?>">
<a href="<?= $this->url; ?>" title="<?= $this->linkTitle; ?>" target="<?= $this->target; ?>" <?php if($this->rel): ?>rel="<?= $this->rel; ?>"<?php endif; ?> <?php if($this->hrefclass): ?>class="<?= $this->hrefclass; ?>"<?php endif; ?>
<figure class="image"><?= $this->image; ?></figure>
<a href="<?= $this->url; ?>" title="<?= $this->linkTitle; ?>" target="<?= $this->target; ?>" <?php if($this->rel): ?>rel="<?= $this->rel; ?>"<?php endif; ?> <?php if($this->hrefclass): ?>class="<?= $this->hrefclass; ?>"<?php endif; ?>>

<figure class="image_container">

<?php $this->insert('picture_default', $this->picture); ?>

<?php if ($this->caption): ?>
<figcaption class="caption" style="width:<?= $this->arrSize[0]; ?>px"><?= $this->caption; ?></figcaption>
<?php endif; ?>

</figure>

</a>
</li>

0 comments on commit 10e61df

Please sign in to comment.