Add edit button to weblink details view

This commit is contained in:
Tuan Pham Ngoc 2021-08-15 19:01:39 +07:00
parent d18740065b
commit efa61dea5b
2 changed files with 20 additions and 0 deletions

View File

@ -63,6 +63,8 @@ class HtmlView extends BaseHtmlView
// Create a shortcut for $item.
$item = $this->item;
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
$offset = $this->state->get('list.offset');
$app->triggerEvent('onContentPrepare', array('com_weblinks.weblink', &$item, &$item->params, $offset));

View File

@ -14,6 +14,15 @@ use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\String\PunycodeHelper;
$weblinkUrl = PunycodeHelper::urlToUTF8($this->item->url);
$user = Factory::getApplication()->getIdentity();
$canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $this->item->catid);
if (!$canEdit)
{
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $this->item->catid);
$canEdit = $canEditOwn && $this->item->created_by == $user->id;
}
?>
<div class="item-page">
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" />
@ -22,6 +31,15 @@ $weblinkUrl = PunycodeHelper::urlToUTF8($this->item->url);
<?php echo $this->escape($this->item->title); ?>
</h2>
</div>
<?php if ($canEdit) : ?>
<div class="icons">
<div class="float-end">
<div>
<?php echo HTMLHelper::_('weblinkicon.edit', $this->item, $this->item->params); ?>
</div>
</div>
</div>
<?php endif; ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $this->item->event->afterDisplayTitle; ?>
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>