Field.php
1 week ago
FieldInterface.php
1 week ago
Fields.php
1 week ago
FieldsInterface.php
1 week ago
Integrator.php
1 week ago
IntegratorIntegration.php
1 week ago
IntegratorInterface.php
1 week ago
Section.php
1 week ago
SectionInterface.php
1 week ago
Sections.php
1 week ago
SectionsInterface.php
1 week ago
Value.php
1 week ago
ValueInterface.php
1 week ago
Fields.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FCF\Free\Integration; |
| 4 | |
| 5 | /** |
| 6 | * . |
| 7 | */ |
| 8 | class Fields implements FieldsInterface { |
| 9 | |
| 10 | /** |
| 11 | * List of field groups. |
| 12 | * |
| 13 | * @var array |
| 14 | */ |
| 15 | private $field_groups; |
| 16 | |
| 17 | /** |
| 18 | * Class constructor. |
| 19 | * |
| 20 | * @param array $field_groups List of field groups. |
| 21 | */ |
| 22 | public function __construct( array $field_groups ) { |
| 23 | $this->field_groups = $field_groups; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Returns list of available fields. |
| 28 | * |
| 29 | * @param string $group_key Optionally key of field group. |
| 30 | * |
| 31 | * @return FieldInterface[] List of objects with field data. |
| 32 | */ |
| 33 | public function get_available_fields( string $group_key = '' ): array { |
| 34 | $items = []; |
| 35 | foreach ( $this->field_groups as $field_group => $fields ) { |
| 36 | if ( ( $group_key !== '' ) && ( $field_group !== $group_key ) ) { |
| 37 | continue; |
| 38 | } |
| 39 | |
| 40 | foreach ( $fields as $field ) { |
| 41 | $items[] = new Field( $field, $field_group ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return $items; |
| 46 | } |
| 47 | } |
| 48 |