| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikWP - Libraries |
| 4 |
* @subpackage adapter.form |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
JLoader::import('adapter.form.fields.list'); |
| 15 |
|
| 16 |
/** |
| 17 |
* Form field class to handle dropdown fields containing |
| 18 |
* the pages assigned to a specific shortcode of the plugin. |
| 19 |
* |
| 20 |
* @since 10.0 |
| 21 |
*/ |
| 22 |
class JFormFieldMenuItem extends JFormFieldList |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @override |
| 26 |
* Method to get the data to be passed to the layout for rendering. |
| 27 |
* |
| 28 |
* @return array An associative array of display data. |
| 29 |
*/ |
| 30 |
public function getLayoutData() |
| 31 |
{ |
| 32 |
$this->option = array(); |
| 33 |
$this->option[''] = '--'; |
| 34 |
|
| 35 |
if (!empty($this->prefix)) |
| 36 |
{ |
| 37 |
// set modowner with custom prefix |
| 38 |
$this->modowner = $this->prefix; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Force the client path because we need to load the shortcodes model |
| 43 |
* always from the back-end folder. |
| 44 |
* |
| 45 |
* An issue occurred since WP 5.8, after the refactoring of the widgets |
| 46 |
* management page, where the client now results to be "site" in place |
| 47 |
* of "admin". |
| 48 |
* |
| 49 |
* @since 10.1.34 |
| 50 |
*/ |
| 51 |
$model = JModel::getInstance($this->modowner, 'shortcodes', 'admin'); |
| 52 |
|
| 53 |
if ($model) |
| 54 |
{ |
| 55 |
foreach ($model->all() as $item) |
| 56 |
{ |
| 57 |
if ($item->post_id) |
| 58 |
{ |
| 59 |
$this->option[$item->post_id] = get_the_title($item->post_id) . " - {$item->type}"; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return parent::getLayoutData(); |
| 65 |
} |
| 66 |
} |
| 67 |
|