formbuilder.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 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 | /** |
| 15 | * This class extends the CronFormBuilder methods to create |
| 16 | * a custom structure of the configuration fields. |
| 17 | * |
| 18 | * @see VAPCronFormBuilder |
| 19 | * @since 1.5 |
| 20 | */ |
| 21 | class VikAppointmentsCronFormBuilder extends VAPCronFormBuilder |
| 22 | { |
| 23 | /** |
| 24 | * Builds the settings form based on the specified fields. |
| 25 | * The form is returned as string, nothing is echoed inside this function. |
| 26 | * |
| 27 | * @param array $args The associative array containing the |
| 28 | * stored values of the settings. |
| 29 | * |
| 30 | * @return string The Html structure of the form. |
| 31 | */ |
| 32 | public function build($args = array()) |
| 33 | { |
| 34 | $fields = array(); |
| 35 | |
| 36 | foreach ($this->getFields() as $field) |
| 37 | { |
| 38 | if ($field->getType() == VAPCronFormField::HTML) |
| 39 | { |
| 40 | // if the type of the field is HTML register constraint |
| 41 | // to display the specified value |
| 42 | $field->addConstraint('html', $field->getDefaultValue()); |
| 43 | } |
| 44 | else if ($field->getType() == VAPCronFormField::SEPARATOR) |
| 45 | { |
| 46 | // if the type of the field is SEPARATOR register constraints |
| 47 | // to hide the label and use a specific style |
| 48 | $field->addConstraint('class', 'custom-field'); |
| 49 | $field->addConstraint('hidden', true); |
| 50 | } |
| 51 | |
| 52 | // register HTML attributes of field within the list |
| 53 | $fields[$field->getName()] = $field->toArray(); |
| 54 | } |
| 55 | |
| 56 | // prepare display data |
| 57 | $data = array( |
| 58 | 'fields' => $fields, |
| 59 | 'params' => $args, |
| 60 | 'prefix' => $this->classname ? rtrim($this->classname, '_') . '_' : '', |
| 61 | ); |
| 62 | |
| 63 | // render by using the apposite layout |
| 64 | return JLayoutHelper::render('form.fields', $data); |
| 65 | } |
| 66 | } |
| 67 |