Skip to content

Commit 2c61880

Browse files
Allow Reset Hits For Weblink Item
1 parent 69504ed commit 2c61880

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/administrator/components/com_weblinks/forms/weblink.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@
5858

5959
<field
6060
name="hits"
61-
type="text"
61+
type="hits"
6262
label="JGLOBAL_HITS"
63-
class="readonly"
64-
readonly="true"
65-
filter="unset"
63+
addfieldprefix="Joomla\Component\Weblinks\Administrator\Field"
6664
default="0"
6765
/>
6866

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage com_weblinks
6+
*
7+
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Component\Weblinks\Administrator\Field;
12+
13+
use Joomla\CMS\Form\FormField;
14+
use Joomla\CMS\Language\Text;
15+
16+
// phpcs:disable PSR1.Files.SideEffects
17+
\defined('_JEXEC') or die;
18+
// phpcs:enable PSR1.Files.SideEffects
19+
20+
/**
21+
* Hits field for Weblinks.
22+
* Renders a read-only input for hits and a reset button.
23+
*
24+
* @since __DEPLOY_VERSION__
25+
*/
26+
class HitsField extends FormField
27+
{
28+
/**
29+
* The form field type.
30+
*
31+
* @var string
32+
* @since __DEPLOY_VERSION__
33+
*/
34+
protected $type = 'Hits';
35+
36+
/**
37+
* Method to get the field input markup.
38+
*
39+
* @return string The field input markup.
40+
*
41+
* @since __DEPLOY_VERSION__
42+
*/
43+
protected function getInput()
44+
{
45+
$onclick = ' onclick="document.getElementById(\'' . $this->id . '\').value=\'0\';"';
46+
47+
return '<div class="input-group"><input class="form-control" type="text" name="' . $this->name . '" id="' . $this->id . '" value="'
48+
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly">'
49+
. '<button type="button" class="btn btn-secondary" ' . $onclick . '>'
50+
. '<span class="icon-sync" aria-hidden="true"></span> ' . Text::_('JRESET') . '</button></div>';
51+
}
52+
}

0 commit comments

Comments
 (0)