plugin install
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API\Fluent;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\Fluent\Layers\Fluent_Theme_Layer;
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
|
||||
|
||||
/**
|
||||
* Wrapper around the Fluent_Theme_Layer that provides fluent access (each call returns the class so
|
||||
* future calls can be chained).
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class Theme_Layer_Builder {
|
||||
|
||||
private $layer;
|
||||
|
||||
/**
|
||||
* Gathers the various dependencies
|
||||
*
|
||||
* NOTE: we don't use DI here because this class is instantiated in various places, and it would make
|
||||
* the process onerous for third-party usage.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$def_factory = \GFForms::get_service_container()->get( GF_Theme_Layers_Provider::DEFINITION_ENGINE_FACTORY );
|
||||
$output_factory = \GFForms::get_service_container()->get( GF_Theme_Layers_Provider::OUTPUT_ENGINE_FACTORY );
|
||||
$this->layer = new Fluent_Theme_Layer( $def_factory, $output_factory );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the layer's engines and add the layer to the list of registered theme layers.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
$layer = $this->layer;
|
||||
$layer->init_engines();
|
||||
add_filter( 'gform_registered_theme_layers', function ( $layers ) use ( $layer ) {
|
||||
$layers[] = $layer;
|
||||
|
||||
return $layers;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for name.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_name( $name ) {
|
||||
$this->layer->set_name( $name );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for title.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $title
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_short_title( $title ) {
|
||||
$this->layer->set_short_title( $title );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for priority.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_priority( $priority ) {
|
||||
$this->layer->set_priority( $priority );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_icon( $icon ) {
|
||||
$this->layer->set_icon( $icon );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for fields.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $fields
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_settings_fields( $fields ) {
|
||||
$this->layer->set_settings_fields( $fields );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for overidden fields.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $fields
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_overidden_fields( $fields ) {
|
||||
$this->layer->set_overidden_fields( $fields );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for css properties.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $properties
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_form_css_properties( $properties ) {
|
||||
$this->layer->set_form_css_properties( $properties );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for scripts.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $scripts
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_scripts( $scripts ) {
|
||||
$this->layer->set_scripts( $scripts );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for styles.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $styles
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_styles( $styles ) {
|
||||
$this->layer->set_styles( $styles );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for block settings.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $settings
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function set_block_settings( $settings ) {
|
||||
$this->layer->set_block_settings( $settings );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API\Fluent\Layers;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\GF_All_Access_Theme_Layer;
|
||||
|
||||
/**
|
||||
* Theme Layer set up to be used in a fluent context. This layer extends GF_All_Access_Theme_Layer,
|
||||
* which allows it to have access to all available traits and engines.
|
||||
*
|
||||
* This layer mostly acts as a middleware to pass values from the fluent builder to the layer.
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class Fluent_Theme_Layer extends GF_All_Access_Theme_Layer {
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/// Getters ////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public function settings_fields() {
|
||||
return $this->_settings_fields;
|
||||
}
|
||||
|
||||
public function block_settings() {
|
||||
return $this->_block_settings;
|
||||
}
|
||||
|
||||
public function overriden_fields() {
|
||||
return $this->_overidden_fields;
|
||||
}
|
||||
|
||||
public function form_css_properties( $form_id = 0, $settings = array(), $block_settings = array(), $form = array() ) {
|
||||
if ( is_callable( $this->_form_css_properties ) ) {
|
||||
return call_user_func_array( $this->_form_css_properties, array( $form_id, $settings, $block_settings, $form ) );
|
||||
}
|
||||
|
||||
return $this->_form_css_properties;
|
||||
}
|
||||
|
||||
public function scripts( $form, $ajax, $settings, $block_settings = array() ) {
|
||||
return is_callable( $this->_scripts ) ? call_user_func_array( $this->_scripts, array(
|
||||
$form,
|
||||
$ajax,
|
||||
$settings,
|
||||
$block_settings,
|
||||
) ) : array();
|
||||
}
|
||||
|
||||
public function styles( $form, $ajax, $settings, $block_settings = array() ) {
|
||||
return is_callable( $this->_styles ) ? call_user_func_array( $this->_styles, array(
|
||||
$form,
|
||||
$ajax,
|
||||
$settings,
|
||||
$block_settings,
|
||||
) ) : array();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/// Setters ////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public function set_settings_fields( $fields ) {
|
||||
$this->_settings_fields = $fields;
|
||||
}
|
||||
|
||||
public function set_block_settings( $settings ) {
|
||||
$this->_block_settings = $settings;
|
||||
}
|
||||
|
||||
public function set_overidden_fields( $fields ) {
|
||||
$this->_overidden_fields = $fields;
|
||||
}
|
||||
|
||||
public function set_form_css_properties( $properties ) {
|
||||
$this->_form_css_properties = $properties;
|
||||
}
|
||||
|
||||
public function set_scripts( $scripts ) {
|
||||
$this->_scripts = $scripts;
|
||||
}
|
||||
|
||||
public function set_styles( $styles ) {
|
||||
$this->_styles = $styles;
|
||||
}
|
||||
|
||||
public function set_name( $name ) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function set_priority( $priority ) {
|
||||
$this->priority = $priority;
|
||||
}
|
||||
|
||||
public function set_short_title( $title ) {
|
||||
$this->short_title = $title;
|
||||
}
|
||||
|
||||
public function set_icon( $icon ) {
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user