PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Form / LegacyConsumer / FieldView.php
FieldView.php
74 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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