| 1 |
<?php |
| 2 |
defined('ABSPATH') || die('Restricted Access'); |
| 3 |
|
| 4 |
include_once __DIR__.DIRECTORY_SEPARATOR.'AcymJFormField.php'; |
| 5 |
|
| 6 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Joomla specific class naming with imposed prefix "JFormField". |
| 7 |
class JFormFieldArticle extends AcymJFormField |
| 8 |
{ |
| 9 |
public function __construct($form = null) |
| 10 |
{ |
| 11 |
$this->type = 'article'; |
| 12 |
parent::__construct($form); |
| 13 |
} |
| 14 |
|
| 15 |
public function getInput() |
| 16 |
{ |
| 17 |
$modalId = 'acym_article_'.$this->id; |
| 18 |
$callback = 'jSelectArticle_'.$this->id; |
| 19 |
|
| 20 |
$title = ''; |
| 21 |
$value = intval($this->value); |
| 22 |
if (!empty($value)) { |
| 23 |
$title = acym_CMSArticleTitle($value); |
| 24 |
} |
| 25 |
|
| 26 |
// Callback function from the modal to the main window |
| 27 |
acym_addScript( |
| 28 |
true, |
| 29 |
" |
| 30 |
function $callback(id, title, catid, object, url, language) { |
| 31 |
window.processModalSelect('Article', '".$this->id."', id, title, catid, object, url, language); |
| 32 |
toggle_$callback(id); |
| 33 |
jQuery('#".$modalId."').modal('hide'); |
| 34 |
} |
| 35 |
|
| 36 |
function toggle_$callback(selection) { |
| 37 |
if (selection && selection > 0) { |
| 38 |
jQuery('#button_$modalId').hide(); |
| 39 |
jQuery('#clear_$modalId').show(); |
| 40 |
} else { |
| 41 |
jQuery('#".$this->id."_name').val(''); |
| 42 |
jQuery('#".$this->id."_id').val(''); |
| 43 |
|
| 44 |
jQuery('#button_$modalId').show(); |
| 45 |
jQuery('#clear_$modalId').hide(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
jQuery(function($){ |
| 50 |
toggle_$callback($value); |
| 51 |
});" |
| 52 |
); |
| 53 |
|
| 54 |
$html = '<span class="input-append">'; |
| 55 |
$html .= '<input class="input-medium" id="'.$this->id.'_name" type="text" value="'.esc_attr($title).'" disabled="disabled" size="35" />'; |
| 56 |
$urlSelect = acym_articleSelectionPage().'&function='.$callback; |
| 57 |
$html .= acym_cmsModal( |
| 58 |
true, |
| 59 |
$urlSelect, |
| 60 |
'ACYM_SELECT', |
| 61 |
true, |
| 62 |
acym_translation('ACYM_SELECT_AN_ARTICLE'), |
| 63 |
$modalId |
| 64 |
); |
| 65 |
$html .= '<a id="clear_'.$modalId.'" class="btn hasTooltip" data-toggle="modal" role="button" onclick="toggle_'.$callback.'(0);">'.acym_translation('ACYM_CLEAR').'</a>'; |
| 66 |
$html .= '</span>'; |
| 67 |
|
| 68 |
$html .= '<input type="hidden" id="'.$this->id.'_id" name="'.$this->name.'" value="'.$value.'" />'; |
| 69 |
|
| 70 |
return $html; |
| 71 |
} |
| 72 |
|
| 73 |
public function getLabel() |
| 74 |
{ |
| 75 |
return str_replace($this->id, $this->id.'_id', parent::getLabel()); |
| 76 |
} |
| 77 |
} |
| 78 |
|