Skip to content

Commit

Permalink
[4.3] Several fixes to single tag view from com_tags (#39113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar authored Nov 29, 2022
1 parent eddd32d commit 97e6593
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 169 deletions.
11 changes: 11 additions & 0 deletions administrator/components/com_tags/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@
<option value="current_language">JCURRENT</option>
</field>

<field
name="record_hits"
type="radio"
label="JGLOBAL_RECORD_HITS_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

</fieldset>

<fieldset
Expand Down
9 changes: 9 additions & 0 deletions components/com_tags/src/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Joomla\Component\Tags\Site\Controller;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\BaseController;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -56,6 +57,14 @@ public function display($cachable = false, $urlparams = false)
'lang' => 'CMD'
);

if (
$vName === 'tag'
&& ComponentHelper::getParams('com_tags')->get('record_hits', 1) == 1
&& $model = $this->getModel($vName)
) {
$model->hit();
}

return parent::display($cachable, $safeurlparams);
}
}
72 changes: 34 additions & 38 deletions components/com_tags/src/Model/TagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@
class TagModel extends ListModel
{
/**
* The tags that apply.
* The list of items associated with the tags.
*
* @var object
* @var array
* @since 3.1
*/
protected $tag = null;
protected $items = null;

/**
* The list of items associated with the tags.
* Array of tags
*
* @var array
* @since 3.1
* @var CMSObject[]
* @since __DEPLOY_VERSION__
*/
protected $items = null;
protected $item = [];

/**
* Constructor.
Expand Down Expand Up @@ -97,31 +97,29 @@ public function getItems()
// Invoke the parent getItems method to get the main list
$items = parent::getItems();

if (!empty($items)) {
foreach ($items as $item) {
$item->link = RouteHelper::getItemRoute(
$item->content_item_id,
$item->core_alias,
$item->core_catid,
$item->core_language,
$item->type_alias,
$item->router
);

// Get display date
switch ($this->state->params->get('tag_list_show_date')) {
case 'modified':
$item->displayDate = $item->core_modified_time;
break;

case 'created':
$item->displayDate = $item->core_created_time;
break;

default:
$item->displayDate = ($item->core_publish_up == 0) ? $item->core_created_time : $item->core_publish_up;
break;
}
foreach ($items as $item) {
$item->link = RouteHelper::getItemRoute(
$item->content_item_id,
$item->core_alias,
$item->core_catid,
$item->core_language,
$item->type_alias,
$item->router
);

// Get display date
switch ($this->state->params->get('tag_list_show_date')) {
case 'modified':
$item->displayDate = $item->core_modified_time;
break;

case 'created':
$item->displayDate = $item->core_created_time;
break;

default:
$item->displayDate = ($item->core_publish_up == 0) ? $item->core_created_time : $item->core_publish_up;
break;
}
}

Expand Down Expand Up @@ -268,9 +266,7 @@ protected function populateState($ordering = 'c.core_title', $direction = 'ASC')
*/
public function getItem($pk = null)
{
if (!isset($this->item)) {
$this->item = [];

if (!count($this->item)) {
if (empty($pk)) {
$pk = $this->getState('tag.id');
}
Expand Down Expand Up @@ -306,10 +302,10 @@ public function getItem($pk = null)
return false;
}
}
}

if (!$this->item) {
throw new \Exception(Text::_('COM_TAGS_TAG_NOT_FOUND'), 404);
if (count($this->item) != count($idsArray)) {
throw new \Exception(Text::_('COM_TAGS_TAG_NOT_FOUND'), 404);
}
}

return $this->item;
Expand Down
Loading

0 comments on commit 97e6593

Please sign in to comment.