-
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.
- Loading branch information
Showing
3 changed files
with
143 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,76 @@ | ||
<?php | ||
|
||
|
||
namespace JFBCore; | ||
|
||
|
||
trait BaseRenderField { | ||
|
||
public $args; | ||
public $args_map; | ||
|
||
abstract public function set_up( ...$args ); | ||
|
||
abstract public function render_field( $attrs_string ); | ||
|
||
/** | ||
* It used in JetFormBuilder Render\Base for naming field template | ||
* And in JetEngine & jetFormBuilder it used for naming wp.hook | ||
* | ||
* @return string | ||
*/ | ||
abstract public function get_name(); | ||
|
||
public function attributes_values() { | ||
return array(); | ||
} | ||
|
||
public function attributes_map() { | ||
return array(); | ||
} | ||
|
||
public function args_map() { | ||
return array(); | ||
} | ||
|
||
private function default_args_map() { | ||
$this->args_map = array_merge_recursive( array( | ||
'required' => '', | ||
'name' => 'field_name', | ||
'default' => '' | ||
), $this->args_map() ); | ||
} | ||
|
||
final public function get_arg( $key ) { | ||
return ( isset( $this->args[ $key ] ) ? $this->args[ $key ] : $this->args_map[ $key ] ); | ||
} | ||
|
||
private function save_attributes() { | ||
$attributes = apply_filters( "jet-fb/attributes/{$this->get_name()}", $this->get_attributes_map() ); | ||
|
||
foreach ( $attributes as $name => $value ) { | ||
$this->add_attribute( $name, $value ); | ||
} | ||
} | ||
|
||
final public function get_attributes_map() { | ||
return array_merge_recursive( $this->attributes_map(), $this->attributes_values() ); | ||
} | ||
|
||
final public function get_rendered() { | ||
$this->default_args_map(); | ||
$this->save_attributes(); | ||
|
||
return $this->render_field( $this->get_attributes_string_save() ); | ||
} | ||
|
||
public function get_args( $args_names ) { | ||
$response = array(); | ||
|
||
foreach ( $args_names as $args_name ) { | ||
$response[ $args_name ] = $this->get_arg( $args_name ); | ||
} | ||
|
||
return $response; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
|
||
namespace JFBCore\JetEngine; | ||
|
||
|
||
use JFBCore\AttributesTrait; | ||
use JFBCore\BaseRenderField; | ||
|
||
trait RenderField { | ||
|
||
use AttributesTrait; | ||
use BaseRenderField; | ||
|
||
private $builder; | ||
|
||
public function set_up( ...$args ) { | ||
$this->args = $args[0]; | ||
$this->builder = $args[1]; | ||
|
||
return $this; | ||
} | ||
|
||
public function attributes_map() { | ||
return array( | ||
'class' => array( 'jet-form__field' ), | ||
'required' => $this->builder->get_required_val( $this->args ), | ||
'name' => $this->builder->get_field_name( $this->get_arg( 'name' ) ), | ||
'id' => $this->builder->get_field_id( $this->args ), | ||
'data-field-name' => $this->get_arg( 'name' ), | ||
'value' => $this->get_arg( 'default' ), | ||
); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
|
||
namespace JFBCore\JetFormBuilder; | ||
|
||
|
||
|
||
|
||
use JFBCore\BaseRenderField; | ||
|
||
trait RenderBlock { | ||
|
||
use BaseRenderField; | ||
|
||
public function set_up( ...$args ) { | ||
$this->args = $this->block_type->block_attrs; | ||
|
||
return $this; | ||
} | ||
|
||
public function attributes_map() { | ||
return array( | ||
'class' => array( 'jet-form-builder__field' ), | ||
'required' => $this->block_type->get_required_val( $this->args ), | ||
'name' => $this->block_type->get_field_name( $this->get_arg( 'name' ) ), | ||
'id' => $this->block_type->get_field_id( $this->args ), | ||
'data-field-name' => $this->get_arg( 'name' ), | ||
'value' => $this->get_arg( 'default' ), | ||
); | ||
} | ||
|
||
|
||
} |