Skip to content

Commit 7d1e4ac

Browse files
authored
Merge pull request NeoRazorX#1874 from Yopli2k/BaseWidget
Añadido nuevo atributo a los widgets: fieldclick
2 parents 3c99d9b + 41cc03b commit 7d1e4ac

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Core/Lib/Widget/BaseWidget.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class BaseWidget extends VisualItem
3939
*/
4040
public $fieldname;
4141

42+
public $fieldclick;
43+
4244
/**
4345
* @var string
4446
*/
@@ -79,6 +81,11 @@ class BaseWidget extends VisualItem
7981
*/
8082
protected $value;
8183

84+
/**
85+
* @var mixed
86+
*/
87+
protected $valueOnClick = null;
88+
8289
/**
8390
* @param array $data
8491
*/
@@ -87,6 +94,7 @@ public function __construct($data)
8794
parent::__construct($data);
8895
$this->autocomplete = false;
8996
$this->fieldname = $data['fieldname'];
97+
$this->fieldclick = $data['fieldclick'] ?? '';
9098
$this->icon = $data['icon'] ?? '';
9199
$this->onclick = $data['onclick'] ?? '';
92100
$this->readonly = $data['readonly'] ?? 'false';
@@ -264,12 +272,13 @@ protected function loadOptions($children): void
264272
*/
265273
protected function onclickHtml($inside, $titleurl = '')
266274
{
267-
if (empty($this->onclick) || is_null($this->value)) {
275+
$value = empty($this->valueOnClick) ? $this->value : $this->valueOnClick;
276+
if (empty($this->onclick) || is_null($value)) {
268277
return empty($titleurl) ? $inside : '<a href="' . $titleurl . '">' . $inside . '</a>';
269278
}
270279

271-
$params = strpos($this->onclick, '?') !== false ? '&' : '?';
272-
return '<a href="' . Tools::config('route') . '/' . $this->onclick . $params . 'code=' . rawurlencode($this->value)
280+
$params = str_contains($this->onclick, '?') ? '&' : '?';
281+
return '<a href="' . Tools::config('route') . '/' . $this->onclick . $params . 'code=' . rawurlencode($value)
273282
. '" class="cancelClickable">' . $inside . '</a>';
274283
}
275284

@@ -291,6 +300,9 @@ protected function readonly(): bool
291300
protected function setValue($model)
292301
{
293302
$this->value = $model->{$this->fieldname} ?? null;
303+
if (false === empty($this->fieldclick)) {
304+
$this->valueOnClick = $model->{$this->fieldclick} ?? null;
305+
}
294306
}
295307

296308
/**

0 commit comments

Comments
 (0)