Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\JForm;
defined('_JEXEC') or die;
// Display Joomla Form Field - Label, Form Control (Input), Description
class TField
{
public $field;
public $config = [];
public function __construct($field, $config = [])
{
// $field is joomla form field object: __get(), getAttribute, __set
// $config - label_class, parent_class, show_label, show_description
$this->field = $field;
$this->config = $config;
}
public function get_output()
{
// Parent Class
$parent_class[] = 'mb-3';
$parent_class[] = $this->field->getAttribute('parentclass') ?? '';
$parent_class[] = $this->config['parent_class'] ?? '';
$this->field->__set('parentclass', implode(' ', $parent_class));
$output = '';
$this->get_label();
$this->get_input();
$options = [];
if (isset($this->config['show_label']) && !$this->config['show_label'])
{
$options['hiddenLabel'] = 'true';
}
if (isset($this->config['show_description']) && !$this->config['show_description'])
{
$options['hiddenDescription'] = 'true';
}
$output .= $this->field->renderField($options);
return $output;
}
public function get_label()
{
// Label Class
$label_class[] = $this->field->getAttribute('labelclass') ?? '';
$label_class[] = 'form-label';
$label_class[] = $this->config['label_class'] ?? '';
$this->field->__set('labelclass', implode(' ', $label_class));
//return $this->field->label;
}
public function get_input()
{
return $this->field->__get('input');
}
public function get_description()
{
$hiddenDescription = $this->field->getAttribute('hiddenDescription') == 'true';
if (!$this->field->description || $hiddenDescription)
{
return;
}
$output = '<small class="form-text">' . $this->field->description . '</small>';
return $output;
}
}
/*
$this->field->renderField();
<div class="control-group"> // parentclass
<div class="control-label">
<label> </label> // labelclass
</div>
<div class="controls">
<input> // class
</div>
</div>
*/