| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
use AcyMailing\Classes\ListClass; |
| 5 |
|
| 6 |
include_once __DIR__.DIRECTORY_SEPARATOR.'AcymJFormField.php'; |
| 7 |
|
| 8 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Joomla specific class naming with imposed prefix "JFormField". |
| 9 |
class JFormFieldLists extends AcymJFormField |
| 10 |
{ |
| 11 |
public function __construct($form = null) |
| 12 |
{ |
| 13 |
$this->type = 'lists'; |
| 14 |
parent::__construct($form); |
| 15 |
} |
| 16 |
|
| 17 |
public function getInput() |
| 18 |
{ |
| 19 |
|
| 20 |
$listClass = new ListClass(); |
| 21 |
$lists = $listClass->getAllWithoutManagement(); |
| 22 |
foreach ($lists as $i => $oneList) { |
| 23 |
if ($oneList->active == 0) { |
| 24 |
unset($lists[$i]); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
// In Joomla, when the user chooses to empty a field, it sets the default value of this field... that's not what we want |
| 29 |
if (ACYM_CMS == 'joomla' && $this->value === 'All' && !empty($this->form)) { |
| 30 |
$formId = $this->form->getData()->get('id'); |
| 31 |
if (!empty($formId)) { |
| 32 |
$this->value = ''; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if (is_string($this->value)) { |
| 37 |
$this->value = explode(',', $this->value); |
| 38 |
} |
| 39 |
|
| 40 |
if (in_array('None', $this->value)) { |
| 41 |
$this->value = []; |
| 42 |
} |
| 43 |
if (in_array('All', $this->value)) { |
| 44 |
$visibleLists = []; |
| 45 |
foreach ($lists as $listId => $oneList) { |
| 46 |
if ($oneList->visible == 0) continue; |
| 47 |
|
| 48 |
$visibleLists[] = $listId; |
| 49 |
} |
| 50 |
$this->value = $visibleLists; |
| 51 |
} |
| 52 |
|
| 53 |
return acym_selectMultiple( |
| 54 |
$lists, |
| 55 |
$this->name, |
| 56 |
$this->value, |
| 57 |
[ |
| 58 |
'class' => 'acym_simple_select2', |
| 59 |
'id' => $this->name, |
| 60 |
], |
| 61 |
'id', |
| 62 |
'name' |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
|