| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Form; |
| 4 |
|
| 5 |
use FluentForm\App\Services\FormParser; |
| 6 |
|
| 7 |
class FormFieldsParser |
| 8 |
{ |
| 9 |
protected static $forms = array(); |
| 10 |
|
| 11 |
public static function getFields($form, $asArray = false) |
| 12 |
{ |
| 13 |
return static::parse('fields', $form, $asArray); |
| 14 |
} |
| 15 |
|
| 16 |
public function getInputs($form, $with = []) |
| 17 |
{ |
| 18 |
return static::parse('inputs', $form, $with); |
| 19 |
} |
| 20 |
|
| 21 |
public function getEntryInputs($form, $with = ['admin_label']) |
| 22 |
{ |
| 23 |
return static::parse('entry_inputs', $form, $with); |
| 24 |
} |
| 25 |
|
| 26 |
public function parse($key, $form, $with) |
| 27 |
{ |
| 28 |
if (!isset(static::$forms[$form->id])) { |
| 29 |
static::$forms[$form->id] = array(); |
| 30 |
} |
| 31 |
|
| 32 |
if (!isset(static::$forms[$form->id][$key])) { |
| 33 |
$parser = new FormParser($form); |
| 34 |
$method = str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); |
| 35 |
static::$forms[$form->id][$key] = $parser->{'get'.$method}($with); |
| 36 |
} |
| 37 |
|
| 38 |
return static::$forms[$form->id][$key]; |
| 39 |
} |
| 40 |
|
| 41 |
public static function getAdminLabels($form, $fields = []) |
| 42 |
{ |
| 43 |
if (!isset(static::$forms[$form->id])) { |
| 44 |
static::$forms[$form->id] = array(); |
| 45 |
} |
| 46 |
|
| 47 |
if (!isset(static::$forms[$form->id]['admin_labels'])) { |
| 48 |
$parser = new FormParser($form); |
| 49 |
static::$forms[$form->id]['admin_labels'] = $parser->getAdminLabels($fields); |
| 50 |
} |
| 51 |
|
| 52 |
return static::$forms[$form->id]['admin_labels']; |
| 53 |
} |
| 54 |
} |