-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RegisterSingleField for JetEngine Forms
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
|
||
namespace JFBCore\JetEngine; | ||
|
||
|
||
trait RegisterSingleField { | ||
|
||
private function add_hooks() { | ||
add_filter( | ||
'jet-engine/forms/booking/field-types', | ||
array( $this, 'register_form_fields' ) | ||
); | ||
add_action( | ||
"jet-engine/forms/booking/field-template/{$this->get_id()}", | ||
array( $this, 'get_field_template' ), | ||
10, 3 | ||
); | ||
add_action( | ||
'jet-engine/forms/edit-field/before', | ||
array( $this, 'render_field_edit' ) | ||
); | ||
} | ||
|
||
public static function register() { | ||
if ( function_exists( 'jet_engine' ) ) { | ||
( new static() )->add_hooks(); | ||
} | ||
} | ||
|
||
|
||
abstract public function get_id(); | ||
|
||
abstract public function get_title(); | ||
|
||
abstract public function get_field_template(); | ||
|
||
abstract public function render_field_edit(); | ||
|
||
final public function register_form_fields( $fields ) { | ||
$fields[ $this->get_id() ] = $this->get_title(); | ||
|
||
return $fields; | ||
} | ||
|
||
} |