Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] Several fixes to single tag view from com_tags #39113

Merged
merged 11 commits into from
Nov 29, 2022
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
10 changes: 10 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,15 @@ public function display($cachable = false, $urlparams = false)
'lang' => 'CMD'
);

if ($vName === 'tag') {
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
// Get/Create the model
if ($model = $this->getModel($vName)) {
if (ComponentHelper::getParams('com_tags')->get('record_hits', 1) == 1) {
$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);
}
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
}

return $this->item;
Expand Down
Loading