Skip to content

Commit

Permalink
Added RegisterSingleField for JetEngine Forms
Browse files Browse the repository at this point in the history
  • Loading branch information
girafffee committed Mar 26, 2021
1 parent 2ca458f commit 8991e34
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/JetEngine/RegisterSingleField.php
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;
}

}

0 comments on commit 8991e34

Please sign in to comment.