Commands
4 years ago
templates
4 years ago
FieldView.php
4 years ago
FilterCallbackCollection.php
4 years ago
ServiceProvider.php
4 years ago
TemplateHooks.php
4 years ago
functions.php
4 years ago
FieldView.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Form\LegacyConsumer; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Types; |
| 6 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 7 | |
| 8 | /** |
| 9 | * @since 2.10.2 |
| 10 | */ |
| 11 | class FieldView { |
| 12 | const INPUT_TYPE_ATTRIBUTES = [ |
| 13 | Types::PHONE => 'tel', |
| 14 | Types::EMAIL => 'email', |
| 15 | Types::CHECKBOX => 'checkbox', |
| 16 | Types::URL => 'url', |
| 17 | ]; |
| 18 | |
| 19 | /** |
| 20 | * @since 2.10.2 |
| 21 | * |
| 22 | * @param Node $field |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public static function render( Node $field ) { |
| 27 | $type = $field->getType(); |
| 28 | |
| 29 | if ( $type === Types::HIDDEN ) { |
| 30 | include static::getTemplatePath( 'hidden' ); |
| 31 | |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | // Set the class for the input element (used in the templates) |
| 36 | |
| 37 | echo "<div class=\"form-row form-row-wide\" data-field-type=\"{$field->getType()}\" data-field-name=\"{$field->getName()}\">"; |
| 38 | // By default, new fields will use templates/label.html.php and templates/base.html.php |
| 39 | switch ( $type ) { |
| 40 | case Types::HTML: |
| 41 | case Types::CHECKBOX: |
| 42 | case Types::RADIO: // Radio provides its own label |
| 43 | include static::getTemplatePath( $type ); |
| 44 | break; |
| 45 | // These fields need a label and have their own template. |
| 46 | case Types::FILE: |
| 47 | case Types::SELECT: |
| 48 | case Types::TEXTAREA: |
| 49 | include static::getTemplatePath( 'label' ); |
| 50 | include static::getTemplatePath( $type ); |
| 51 | break; |
| 52 | // By default, include a template and use the base input template. |
| 53 | default: |
| 54 | // Used in the template |
| 55 | $typeAttribute = array_key_exists( $type, static::INPUT_TYPE_ATTRIBUTES ) ? static::INPUT_TYPE_ATTRIBUTES[ $type ] : 'text'; |
| 56 | include static::getTemplatePath( 'label' ); |
| 57 | include static::getTemplatePath( 'base' ); |
| 58 | break; |
| 59 | } |
| 60 | echo '</div>'; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @since 2.12.0 |
| 65 | * |
| 66 | * @param string $templateName |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | protected static function getTemplatePath( $templateName ) { |
| 71 | return plugin_dir_path( __FILE__ ) . "/templates/{$templateName}.html.php"; |
| 72 | } |
| 73 | } |
| 74 |