| 1 |
<?php |
| 2 |
/** |
| 3 |
* Kit Form Builder Email Field Block class. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Kit Form Builder Email Field Block for Gutenberg. |
| 11 |
* |
| 12 |
* @package ConvertKit |
| 13 |
* @author ConvertKit |
| 14 |
*/ |
| 15 |
class ConvertKit_Block_Form_Builder_Field_Email extends ConvertKit_Block_Form_Builder_Field { |
| 16 |
|
| 17 |
/** |
| 18 |
* The field name. |
| 19 |
* |
| 20 |
* @since 3.0.0 |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
public $field_name = 'email'; |
| 25 |
|
| 26 |
/** |
| 27 |
* The field ID. |
| 28 |
* |
| 29 |
* @since 3.0.0 |
| 30 |
* |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
public $field_id = 'email'; |
| 34 |
|
| 35 |
/** |
| 36 |
* The type of field to render. |
| 37 |
* |
| 38 |
* @since 3.1.4 |
| 39 |
* |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
public $field_type = 'email'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Whether the field is required. |
| 46 |
* |
| 47 |
* @since 3.0.0 |
| 48 |
* |
| 49 |
* @var bool |
| 50 |
*/ |
| 51 |
public $field_required = true; |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns this block's programmatic name, excluding the convertkit- prefix. |
| 55 |
* |
| 56 |
* @since 3.0.0 |
| 57 |
* |
| 58 |
* @return string |
| 59 |
*/ |
| 60 |
public function get_name() { |
| 61 |
|
| 62 |
/** |
| 63 |
* This will register as: |
| 64 |
* - a Gutenberg block, with the name convertkit/form-builder-field-email. |
| 65 |
*/ |
| 66 |
return 'form-builder-field-email'; |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns this block's title. |
| 72 |
* |
| 73 |
* @since 3.1.1 |
| 74 |
*/ |
| 75 |
public function get_title() { |
| 76 |
|
| 77 |
return __( 'Kit Form Builder: Email Field', 'convertkit' ); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns this block's icon. |
| 83 |
* |
| 84 |
* @since 3.1.1 |
| 85 |
*/ |
| 86 |
public function get_icon() { |
| 87 |
|
| 88 |
return 'resources/backend/images/block-icon-form-builder-field-email.svg'; |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Returns this block's Title, Icon, Categories, Keywords and properties. |
| 94 |
* |
| 95 |
* @since 3.0.0 |
| 96 |
* |
| 97 |
* @return array |
| 98 |
*/ |
| 99 |
public function get_overview() { |
| 100 |
|
| 101 |
return array( |
| 102 |
'title' => $this->get_title(), |
| 103 |
'description' => __( 'Adds an email field to the Kit Form Builder.', 'convertkit' ), |
| 104 |
'icon' => $this->get_icon(), |
| 105 |
'category' => 'convertkit', |
| 106 |
'keywords' => array( |
| 107 |
__( 'ConvertKit', 'convertkit' ), |
| 108 |
__( 'Kit', 'convertkit' ), |
| 109 |
__( 'Email', 'convertkit' ), |
| 110 |
__( 'Field', 'convertkit' ), |
| 111 |
), |
| 112 |
|
| 113 |
// Function to call when rendering. |
| 114 |
'render_callback' => array( $this, 'render' ), |
| 115 |
|
| 116 |
// Gutenberg: Block Icon in Editor. |
| 117 |
'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-form-builder-field-email.svg' ), |
| 118 |
|
| 119 |
// Gutenberg: Example image showing how this block looks when choosing it in Gutenberg. |
| 120 |
'gutenberg_example_image' => CONVERTKIT_PLUGIN_URL . 'resources/backend/images/block-example-form-builder-field-email.png', |
| 121 |
|
| 122 |
'has_access_token' => true, |
| 123 |
'has_resources' => true, |
| 124 |
); |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Returns this block's Attributes |
| 130 |
* |
| 131 |
* @since 3.0.0 |
| 132 |
* |
| 133 |
* @return array |
| 134 |
*/ |
| 135 |
public function get_attributes() { |
| 136 |
|
| 137 |
// The `required` attribute is not used for this block, |
| 138 |
// as we always require an email address. |
| 139 |
$attributes = parent::get_attributes(); |
| 140 |
unset( $attributes['required'] ); |
| 141 |
return $attributes; |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Returns this block's Fields |
| 147 |
* |
| 148 |
* @since 3.0.0 |
| 149 |
* |
| 150 |
* @return bool|array |
| 151 |
*/ |
| 152 |
public function get_fields() { |
| 153 |
|
| 154 |
// The `required` field is not used for this block, |
| 155 |
// as we always require an email address. |
| 156 |
$fields = parent::get_fields(); |
| 157 |
unset( $fields['required'] ); |
| 158 |
return $fields; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
} |
| 163 |
|