| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
use AcyMailing\Classes\FieldClass; |
| 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 JFormFieldFields extends AcymJFormField |
| 10 |
{ |
| 11 |
public function __construct($form = null) |
| 12 |
{ |
| 13 |
$this->type = 'fields'; |
| 14 |
parent::__construct($form); |
| 15 |
} |
| 16 |
|
| 17 |
public function getInput() |
| 18 |
{ |
| 19 |
|
| 20 |
$fieldsClass = new FieldClass(); |
| 21 |
$allFields = $fieldsClass->getAllFieldsForModuleFront(); |
| 22 |
$fields = []; |
| 23 |
foreach ($allFields as $field) { |
| 24 |
$fields[$field->id] = acym_translation($field->name); |
| 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 == '1') { |
| 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 |
$this->value = array_keys($fields); |
| 45 |
} |
| 46 |
|
| 47 |
return acym_selectMultiple( |
| 48 |
$fields, |
| 49 |
$this->name, |
| 50 |
$this->value, |
| 51 |
[ |
| 52 |
'class' => 'acym_simple_select2', |
| 53 |
'id' => $this->name, |
| 54 |
] |
| 55 |
); |
| 56 |
} |
| 57 |
} |
| 58 |
|