Commands
5 years ago
templates
5 years ago
FieldView.php
5 years ago
FilterCallbackCollection.php
5 years ago
ServiceProvider.php
5 years ago
TemplateHooks.php
5 years ago
functions.php
5 years ago
FieldView.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Form\LegacyConsumer; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\FormField; |
| 6 | |
| 7 | /** |
| 8 | * @since 2.10.2 |
| 9 | */ |
| 10 | class FieldView { |
| 11 | |
| 12 | /** |
| 13 | * @since 2.10.2 |
| 14 | * |
| 15 | * @param FormField $field |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | public static function render( FormField $field ) { |
| 20 | echo "<div class='form-row form-row-wide' data-field-type='{$field->getType()}' data-field-name='{$field->getName()}'>"; |
| 21 | ob_start(); |
| 22 | include plugin_dir_path( __FILE__ ) . '/templates/label.html.php'; |
| 23 | include plugin_dir_path( __FILE__ ) . '/templates/' . $field->getType() . '.html.php'; |
| 24 | echo self::mergeAttributes( ob_get_clean(), $field ); |
| 25 | echo '</div>'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @since 2.10.2 |
| 30 | * |
| 31 | * @param string $html |
| 32 | * @param FormField $field |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | protected static function mergeAttributes( $html, $field ) { |
| 37 | $attributes = array_map( |
| 38 | function( $key, $value ) { |
| 39 | return sprintf( '%s="%s"', $key, esc_attr( $value ) ); |
| 40 | }, |
| 41 | array_keys( $field->getAttributes() ), |
| 42 | array_values( $field->getAttributes() ) |
| 43 | ); |
| 44 | return str_replace( '@attributes', implode( ' ', $attributes ), $html ); |
| 45 | } |
| 46 | } |
| 47 |