Remove all plugins / install base theme

This commit is contained in:
Tony Volpe
2024-06-18 16:14:48 -04:00
parent ecc33d62f0
commit 95cb30b884
7455 changed files with 0 additions and 1722920 deletions

View File

@@ -1,39 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Definition_Engine_Factory;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Output_Engine_Factory;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\GF_Theme_Layer;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits\Enqueues_Assets;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits\Has_Block_Settings;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits\Has_Settings_Fields;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits\Modifies_Markup;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits\Outputs_Form_CSS_Properties;
/**
* Implementation of GF_Theme_Layer which uses all available traits.
*
* @since 2.7
*/
abstract class GF_All_Access_Theme_Layer extends GF_Theme_Layer {
use Has_Settings_Fields;
use Has_Block_Settings;
use Modifies_Markup;
use Outputs_Form_CSS_Properties;
use Enqueues_Assets;
protected $_settings_fields = array();
protected $_block_settings = array();
protected $_overidden_fields = array();
protected $_form_css_properties = array();
protected $_scripts = array();
protected $_styles = array();
public function __construct( Definition_Engine_Factory $definition_engine_factory, Output_Engine_Factory $output_engine_factory ) {
$this->definition_engine_factory = $definition_engine_factory;
$this->output_engine_factory = $output_engine_factory;
}
}

View File

@@ -1,205 +0,0 @@
<?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;
}
/**
* Setter for capability.
*
* @param $capability
*
* @return $this
*/
public function set_capability( $capability ) {
$this->layer->set_capability( $capability );
return $this;
}
}

View File

@@ -1,107 +0,0 @@
<?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;
}
public function set_capability( $capability ) {
$this->form_settings_capability = $capability;
}
}

View File

@@ -1,17 +0,0 @@
<?php
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\JSON\Layers\Json_Theme_Layer;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
function gforms_register_theme_json( $path ) {
$container = GFForms::get_service_container();
$layer = new Json_Theme_Layer( $container->get( GF_Theme_Layers_Provider::DEFINITION_ENGINE_FACTORY ), $container->get( GF_Theme_Layers_Provider::OUTPUT_ENGINE_FACTORY ) );
$layer->set_json( $path );
$layer->init_engines();
add_filter( 'gform_registered_theme_layers', function ( $layers ) use ( $layer ) {
$layers[] = $layer;
return $layers;
} );
}

View File

@@ -1,177 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API\JSON\Layers;
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\GF_All_Access_Theme_Layer;
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\JSON\Rules\GF_Theme_Layer_Rule;
class Json_Theme_Layer extends GF_All_Access_Theme_Layer {
protected $_file;
protected $_json_data;
protected $_rules;
private function process_json() {
$contents = file_get_contents( $this->_file );
$data = json_decode( $contents, true );
if ( empty( $data['gravityforms'] ) ) {
throw new \InvalidArgumentException( 'Invalid theme.json file provided.' );
}
$this->_json_data = $data['gravityforms'];
if ( empty( $this->_json_data['name'] ) || empty( $this->_json_data['short_title'] ) ) {
throw new \InvalidArgumentException( 'theme.json file must have a name and short_title value.' );
}
$this->set_name( $this->_json_data['name'] );
$this->set_short_title( $this->_json_data['short_title'] );
if ( isset( $this->_json_data['settings']['fields']['form'] ) ) {
$this->set_settings_fields( $this->_json_data['settings']['fields']['form'] );
}
if ( isset( $this->_json_data['settings']['fields']['blocks'] ) ) {
$this->set_block_settings( $this->_json_data['settings']['fields']['blocks'] );
}
if ( isset( $this->_json_data['settings']['cssProperties'] ) ) {
$this->set_form_css_properties( $this->_json_data['settings']['cssProperties'] );
}
if ( isset( $this->_json_data['settings']['templateParts'] ) ) {
$this->set_overidden_fields( $this->_json_data['settings']['templateParts'] );
}
if ( isset( $this->_json_data['settings']['assets']['scripts'] ) ) {
$this->set_scripts( $this->_json_data['settings']['assets']['scripts'] );
}
if ( isset( $this->_json_data['settings']['assets']['styles'] ) ) {
$this->set_styles( $this->_json_data['settings']['assets']['styles'] );
}
if ( isset( $this->_json_data['settings']['rules'] ) ) {
$this->set_rules( $this->_json_data['settings']['rules'] );
}
}
private function evaluate_rule( $rule, $settings, $block_settings ) {
if ( is_string( $rule ) && ! isset( $this->_rules[ $rule ] ) ) {
return false;
}
if ( is_string( $rule ) ) {
$rule = $this->_rules[ $rule ];
}
$rule_object = new GF_Theme_Layer_Rule( $rule );
return $rule_object->validate( array( 'form' => $settings, 'blocks' => $block_settings ) );
}
private function filter_values_by_rule( $values, $settings, $block_settings ) {
$self = $this;
return array_filter( $values, function ( $item ) use ( $self, $settings, $block_settings ) {
if ( ! isset( $item['rules'] ) ) {
return true;
}
$rule = $item['rules'];
return $self->evaluate_rule( $rule, $settings, $block_settings );
} );
}
////////////////////////////////////////////////
/// Setters ////////////////////////////////////
////////////////////////////////////////////////
public function set_json( $file ) {
$this->_file = $file;
$this->process_json();
}
public function set_rules( $rules ) {
$this->_rules = $rules;
}
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 ) {
foreach( $styles as &$style ) {
$parsed = str_replace( '%gforms_plugin_url%', \GFCommon::get_base_url(), $style['path'] );
$style['path'] = $parsed;
}
$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;
}
////////////////////////////////////////////////
/// Getters ////////////////////////////////////
////////////////////////////////////////////////
public function settings_fields() {
return array(
array(
'description' => $this->short_title(),
'fields' => $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() ) {
return array();
return $this->filter_values_by_rule( $this->_form_css_properties, $settings, $block_settings );
}
public function scripts( $form, $ajax, $settings, $block_settings = array() ) {
return $this->filter_values_by_rule( $this->_scripts, $settings, $block_settings );
}
public function styles( $form, $ajax, $settings, $block_settings = array() ) {
return $this->filter_values_by_rule( $this->_styles, $settings, $block_settings );
}
}

View File

@@ -1,50 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API\JSON\Rules;
class GF_Theme_Layer_Rule {
private $setting;
private $operator;
private $value;
public function __construct( $args ) {
if ( ! isset( $args['setting'] ) || ! isset( $args['operator'] ) || ! isset( $args['value'] ) ) {
throw new \InvalidArgumentException( 'Rules must have settings, operators, and values.' );
}
$setting_parts = explode( '.', $args['setting'] );
$this->setting = array( 'type' => $setting_parts[0], 'name' => $setting_parts[1] );
$this->operator = $args['operator'];
$this->value = $args['value'];
}
public function validate( $settings ) {
$type = $this->setting['type'];
$name = $this->setting['name'];
if ( ! isset( $settings[ $type ][ $name ] ) ) {
return false;
}
$value = $settings[ $type ][ $name ];
switch ( $this->operator ) {
case '=':
return $value == $this->value;
case '>':
return $value > $this->value;
case '>=':
return $value >= $this->value;
case '<':
return $value < $this->value;
case '<=':
return $value <= $this->value;
case '!=':
return $value != $this->value;
default:
return false;
}
}
}

View File

@@ -1,71 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\API;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines\PHP_Markup_Output_Engine;
/**
* Class used to handle overriding the content of a field or form.
*
* @since 2.7
*/
abstract class View {
protected $engine;
/**
* The Output_Engine for PHP Markup.
*
* @since 2.7
*
* @param PHP_Markup_Output_Engine $engine
*/
public function __construct( $engine ) {
$this->engine = $engine;
}
/**
* Get the markup for an item.
*
* @since 2.7
*
* @param $content
* @param $object
* @param $value
* @param $lead_id
* @param $form_id
*
* @return string
*/
abstract public function get_markup( $content, $object, $value, $lead_id, $form_id );
/**
* Whether this markup override should be in effect.
*
* @since 2.7
*
* @param $object
* @param $form_id
* @param $block_settings
*
* @return bool
*/
public function should_override( $object, $form_id, $block_settings = array() ) {
return true;
}
/**
* Get a setting from the engine.
*
* @since 2.7
*
* @param $key
* @param $form_id
* @param null $default
*
* @return mixed|null
*/
protected function get_setting( $key, $form_id, $default = null ) {
return $this->engine->get_setting( $key, $form_id, $default );
}
}

View File

@@ -1,171 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers;
use \GFAddOn;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\Fluent\Theme_Layer_Builder;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Definition_Engine_Factory;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Output_Engine_Factory;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Assets\Scripts;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Assets\Styles;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\GF_Theme_Layer;
/**
* Class GF_Theme_Layers_Provider
*
* Service provider for the Style Layers.
*
* @since 2.7
*
* @package Gravity_Forms\Gravity_Forms\Theme_Layers;
*/
class GF_Theme_Layers_Provider extends GF_Service_Provider {
// Global services
const THEME_LAYERS = 'theme_layers';
const DEFINITION_ENGINE_FACTORY = 'definition_engine_factory';
const OUTPUT_ENGINE_FACTORY = 'output_engine_factory';
// Definition Engines
const SETTINGS_DEFINITION_ENGINE = 'settings_definition_engine';
const BLOCK_SETTINGS_DEFINITION_ENGINE = 'block_settings_definition_engine';
// Output Engines
const MARKUP_OUTPUT_ENGINE = 'markup_output_engine';
const FORM_CSS_PROPERTIES_OUTPUT_ENGINE = 'form_css_properties_output_engine';
const ASSET_ENQUEUE_OUTPUT_ENGINE = 'asset_enqueue_output_engine';
protected $plugin_path;
protected $namespace;
public function __construct( $plugin_path, $namespace ) {
$this->plugin_path = $plugin_path;
$this->namespace = $namespace;
}
/**
* Register services to the container.
*
* @since 2.7
*
* @param GF_Service_Container $container
*/
public function register( GF_Service_Container $container ) {
$pp = $this->plugin_path;
$ns = $this->namespace;
$this->require_deps();
$container->add( self::DEFINITION_ENGINE_FACTORY, function () {
return new Definition_Engine_Factory();
} );
$container->add( self::OUTPUT_ENGINE_FACTORY, function () use ( $ns ) {
return new Output_Engine_Factory( $ns );
} );
$container->add( self::THEME_LAYERS, function () use ( $container ) {
return function () {
$layers = array();
return apply_filters( 'gform_registered_theme_layers', $layers );
};
} );
}
/**
* Require the dependencies.
*
* @since 2.7
*
* @return void
*/
protected function require_deps() {
// Framework
require_once( dirname( __FILE__ ) . '/framework/class-gf-theme-layer.php' );
require_once( dirname( __FILE__ ) . '/framework/traits/trait-has-settings-fields.php' );
require_once( dirname( __FILE__ ) . '/framework/traits/trait-has-block-settings.php' );
require_once( dirname( __FILE__ ) . '/framework/traits/trait-modifies-markup.php' );
require_once( dirname( __FILE__ ) . '/framework/traits/trait-outputs-form-css-properties.php' );
require_once( dirname( __FILE__ ) . '/framework/traits/trait-enqueues-assets.php' );
require_once( dirname( __FILE__ ) . '/framework/factories/class-definition-engine-factory.php' );
require_once( dirname( __FILE__ ) . '/framework/factories/class-output-engine-factory.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/definition-engines/class-definition-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/definition-engines/class-settings-definition-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/definition-engines/class-block-settings-definition-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/output-engines/class-output-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/output-engines/class-php-markup-output-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/output-engines/class-form-css-properties-output-engine.php' );
require_once( dirname( __FILE__ ) . '/framework/engines/output-engines/class-asset-enqueue-output-engine.php' );
// API
require_once( dirname( __FILE__ ) . '/api/json/functions.php' );
require_once( dirname( __FILE__ ) . '/api/views/class-view.php' );
require_once( dirname( __FILE__ ) . '/api/class-gf-all-access-theme-layer.php' );
require_once( dirname( __FILE__ ) . '/api/fluent/layers/class-fluent-theme-layer.php' );
require_once( dirname( __FILE__ ) . '/api/json/rules/class-gf-theme-layer-rule.php' );
require_once( dirname( __FILE__ ) . '/api/json/layers/class-json-theme-layer.php' );
require_once( dirname( __FILE__ ) . '/api/fluent/class-theme-layer-builder.php' );
// Addon
require_once( dirname( __FILE__ ) . '/class-gf-theme-layers.php' );
}
/**
* Initialize any actions or hooks.
*
* @since 2.7
*
* @param GF_Service_Container $container
*
* @return void
*/
public function init( GF_Service_Container $container ) {
add_action( 'gform_loaded', function () {
GFAddOn::register( GF_Theme_Layers::class );
} );
$this->output_settings( $container );
}
/**
* Add a filter to output our settings when they exist.
*
* @since 2.7
*
* @param GF_Service_Container $container
*
* @return void
*/
public function output_settings( GF_Service_Container $container ) {
add_filter( 'gform_addon_form_settings_fields', function ( $sections, $form ) use ( $container ) {
/**
* @var GF_Theme_Layer[]
*/
$style_layers = $container->get( self::THEME_LAYERS );
$layer_name = rgget( 'theme_layer' );
foreach ( $style_layers as $layer ) {
/**
* @var GF_Theme_Layer $layer
*/
if ( $layer->name() !== $layer_name ) {
continue;
}
if ( empty( $layer->get_definitions()['settings'] ) ) {
continue;
}
return $layer->get_definitions()['settings'];
}
return $sections;
}, 0, 2 );
}
}

View File

@@ -1,128 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\GF_Theme_Layer;
use Gravity_Forms\Gravity_Forms_Conversational_Forms\Style_Layers\GFCF_Style_Layers_Provider;
\GFForms::include_addon_framework();
/**
* Add-on class used to register our Theme Layers and pieces of architecture.
*
* @since 2.7
*/
class GF_Theme_Layers extends \GFAddOn {
protected $_slug = 'gf_theme_layers';
protected $_full_path = __FILE__;
protected $_title = 'Gravity Forms Theme Layers';
protected $_short_title = 'Theme Layers';
/**
* @var object|null $_instance If available, contains an instance of this class.
*/
private static $_instance = null;
/**
* @var GF_Service_Container
*/
protected $container;
/**
* Returns an instance of this class, and stores it in the $_instance property.
*
* @since 2.7
*
* @return GF_Conversational_Forms $_instance An instance of this class.
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function render_uninstall() {
return '';
}
public function set_logging_supported( $plugins ) {
return $plugins;
}
/**
* Add the form settings tab.
*
* @since 2.7
*
* @param $tabs
* @param $form_id
*
* @return array
*/
public function add_form_settings_menu( $tabs, $form_id ) {
/**
* @var GF_Theme_Layer[]
*/
$theme_layers = \GFForms::get_service_container()->get( GF_Theme_Layers_Provider::THEME_LAYERS );
foreach ( $theme_layers as $layer ) {
/**
* @var GF_Theme_Layer $layer
*/
if ( empty( $layer->get_definitions()['settings'] ) ) {
continue;
}
$tabs[] = array(
'name' => $layer->name(),
'label' => $layer->short_title(),
'icon' => $layer->icon(),
'query' => array(
'theme_layer' => $layer->name(),
'subview' => $this->get_slug(),
),
'capabilities' => $layer->get_form_settings_capability(),
);
}
return $tabs;
}
/**
* Form settings fields.
*
* @since 2.7
*
* @param $form
*
* @return array
*/
public function form_settings_fields( $form ) {
return array();
}
/**
* Get the form settings capabilities.
*/
public function get_form_settings_capabilities() {
static $caps;
if ( empty( $caps ) ) {
$theme_layers = \GFForms::get_service_container()->get( GF_Theme_Layers_Provider::THEME_LAYERS );
foreach ( $theme_layers as $layer ) {
/**
* @var GF_Theme_Layer $layer
*/
$caps[ $layer->name() ] = $layer->get_form_settings_capability();
}
}
return rgar( $caps, rgget( 'theme_layer' ) );
}
}

View File

@@ -1,156 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines\Definition_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Definition_Engine_Factory;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories\Output_Engine_Factory;
/**
* GF_Theme_Layer
*
* Provides base functionality for any system which needs to implement a Theme Layer. Can either be
* directly extended or used via the API.
*
* @since 2.7
*/
abstract class GF_Theme_Layer {
protected $name;
protected $icon;
protected $short_title;
protected $priority;
protected $form_settings_capability;
/**
* @var Definition_Engine[]
*/
protected $definition_engines = array();
protected $output_engines = array();
/**
* @var Definition_Engine_Factory
*/
protected $definition_engine_factory;
/**
* @var Output_Engine_Factory
*/
protected $output_engine_factory;
/**
* Constructor
*
* @since 2.7
*
* @param Definition_Engine_Factory $definition_engine_factory
* @param Output_Engine_Factory $output_engine_factory
*
* @return void
*/
public function __construct( Definition_Engine_Factory $definition_engine_factory, Output_Engine_Factory $output_engine_factory ) {
$this->definition_engine_factory = $definition_engine_factory;
$this->output_engine_factory = $output_engine_factory;
$this->init_engines();
}
/**
* Initialize the various engines the current Theme Layer implements.
*
* @since 2.7
*
* @return void
*/
public function init_engines() {
$methods = get_class_methods( $this );
// Traits will define an `add_engine_{engine_name}` method that we can key from here.
foreach ( $methods as $method ) {
if ( strpos( $method, 'add_engine_' ) === false ) {
continue;
}
$this->$method();
}
}
public function output_engines() {
return $this->output_engines;
}
public function output_engine_by_type( $type ) {
$engines_of_type = array_filter( $this->output_engines, function( $engine ) use ( $type ) {
return is_a( $engine, $type );
});
return empty( $engines_of_type ) ? null : array_shift( $engines_of_type );
}
/**
* Get the definitions for this theme layer.
*
* @since 2.7
*
* @return array
*/
public function get_definitions() {
$definitions = array();
foreach ( $this->definition_engines as $engine ) {
if ( ! isset( $definitions[ $engine->type() ] ) ) {
$definitions[ $engine->type() ] = array();
}
$definitions[ $engine->type() ] = array_merge( $definitions[ $engine->type() ], $engine->get_definitions() );
}
return $definitions;
}
/**
* Getter for name
*
* @since 2.7
*
* @return string
*/
public function name() {
return $this->name;
}
/**
* Getter for priority
*
* @since 2.7
*
* @return int
*/
public function priority() {
return $this->priority;
}
/**
* Getter for short_title
*
* @since 2.7
*
* @return string
*/
public function short_title() {
return $this->short_title;
}
public function icon() {
return $this->icon;
}
/**
* Getter for form_settings_capability
*
* @return string
*/
public function get_form_settings_capability() {
return $this->form_settings_capability;
}
}

View File

@@ -1,45 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines;
/**
* Handles defining Settings Fields for the Form block.
*
* @since 2.7
*/
class Block_Settings_Definition_Engine extends Definition_Engine {
protected $type = 'block_settings';
/**
* The settings.
*
* @since 2.7
*
* @var array
*/
protected $settings;
/**
* Setter for block settings.
*
* @since 2.7
*
* @param array $settings
*/
public function set_block_settings( array $settings ) {
$this->settings = $settings;
}
/**
* Getter for settings/definitions.
*
* @since 2.7
*
* @return array
*/
public function get_definitions() {
return $this->settings;
}
}

View File

@@ -1,35 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines;
/**
* Definition_Engines are responsible for adding things that define values, such as
* settings fields, block settings, etc.
*
* @since 2.7
*/
abstract class Definition_Engine {
protected $type;
/**
* Get the registered definitions.
*
* @since 2.7
*
* @return array
*/
abstract public function get_definitions();
/**
* Getter for type.
*
* @since 2.7
*
* @return string
*/
public function type() {
return $this->type;
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines;
/**
* Handles defining Form Settings fields for a theme layer.
*
* @since 2.7
*/
class Settings_Definition_Engine extends Definition_Engine {
protected $type = 'settings';
/**
* @since 2.7
*
* @var array
*/
protected $fields;
/**
* Setter for fields.
*
* @since 2.7
*
* @param array $fields
*/
public function set_fields( array $fields ) {
$this->fields = $fields;
}
/**
* Return the fields defined for this layer.
*
* @since 2.7
*
* @return array
*/
public function get_definitions() {
return $this->fields;
}
}

View File

@@ -1,200 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines;
use GFAPI;
/**
* Handles enqueuing various script and style assets.
*
* @since 2.7
*/
class Asset_Enqueue_Output_Engine extends Output_Engine {
private static $groups = array(
'reset' => array(),
'foundation' => array(),
'framework' => array(),
'theme' => array(),
);
protected $type = 'enqueued_asset';
protected $styles;
protected $scripts;
/**
* Setter for styles.
*
* @since 2.7
*
* @param array $styles
*/
public function set_styles( array $styles ) {
$this->styles = $styles;
}
/**
* Setter for scripts.
*
* @since 2.7
*
* @param array $scripts
*/
public function set_scripts( array $scripts ) {
$this->scripts = $scripts;
}
/**
* Handle output by enqueuing the scripts and styles.
*
* @since 2.7
*
* @return void
*/
public function output() {
$self = $this;
// Enqueue scripts and styles for blocks.
add_action( 'gform_post_enqueue_scripts', function ( $found_forms, $found_blocks, $post ) use ( $self ) {
foreach ( $found_blocks as $block ) {
$settings = $self->get_settings( $block['attrs']['formId'] );
$form = \GFFormsModel::get_form( $block['attrs']['formId'] );
$styles = call_user_func_array( $self->styles, array( $form, false, $settings, $block['attrs'] ) );
$scripts = call_user_func_array( $self->scripts, array( $form, false, $settings, $block['attrs'] ) );
$this->process_form_assets( $styles, $scripts );
}
}, 999, 3 );
// Enqueue scripts and styles for forms that aren't in blocks.
add_action( 'gform_enqueue_scripts', function ( $form, $ajax ) use ( $self ) {
$page_instance = isset( $form['page_instance'] ) ? $form['page_instance'] : - 1;
$settings = $this->get_settings( $form['id'] );
$block_settings = $this->get_block_settings( $form['id'], $page_instance );
// Get the settings from the shortcode attribute or form properties, if they exist.
$shortcode_settings = $this->parse_form_style( $form );
// If we have conflicting block and shortcode settings, block settings take priority.
$style_settings = ! empty( $block_settings ) ? $block_settings : $shortcode_settings;
$styles = call_user_func_array( $self->styles, array( $form, $ajax, $settings, $style_settings ) );
$scripts = call_user_func_array( $self->scripts, array( $form, $ajax, $settings, $style_settings ) );
$this->process_form_assets( $styles, $scripts );
}, 999, 2 );
add_action( 'gform_enqueue_scripts', function () use ( $self ) {
global $wp_styles;
$queued = $wp_styles->queue;
usort( $queued, array( $self, 'sort_enqueues_by_group' ) );
$wp_styles->queue = $queued;
return;
}, 1000, 0 );
}
public function sort_enqueues_by_group( $a, $b ) {
$comp_keys = array_keys( self::$groups );
// Setting these to -1 ensures our assets get enqueued after core/wp/other styles.
$a_key = - 1;
$b_key = - 1;
// Our core assets always need to come first within their respective groups.
$always_first = array(
'gravity_forms_orbital_theme',
'gravity_forms_theme_foundation',
'gravity_forms_theme_framework',
'gravity_forms_theme_reset',
);
// Loop through each asset in a group and find the correct positioning key to use for it.
foreach ( self::$groups as $group => $entries ) {
if ( in_array( $a, $entries ) ) {
$a_key = array_search( $group, $comp_keys );
}
if ( in_array( $b, $entries ) ) {
$b_key = array_search( $group, $comp_keys );
}
// Both have been located, break out of the loop to save performance.
if ( $a_key > -1 && $b_key > -1 ) {
break;
}
}
// Assets are in same group, but $a is a core asset. Move it up.
if ( $a_key == $b_key && in_array( $a, $always_first ) ) {
return - 1;
}
// Assets are in same group, but $b is a core asset. Move it up.
if ( $a_key == $b_key && in_array( $b, $always_first ) ) {
return 1;
}
// Non-gf assets, or assets are in the same group and don't need to be ordered.
if ( $a_key == $b_key ) {
// In PHP < 7.0, usort does odd things to compared values. Get original position to avoid rearraging them.
global $wp_styles;
$queued = $wp_styles->queue;
$a_orig_key = array_search( $a, $queued );
$b_orig_key = array_search( $b, $queued );
return $a_orig_key < $b_orig_key ? - 1 : 1;
}
// Return sorting value based on group assets are in.
return $a_key < $b_key ? - 1 : 1;
}
/**
* Enqueue the styles and scripts for a form.
*
* @since 2.7.4
*
* @param array $styles Styles to enqueue
* @param array $scripts Scripts to enqueue
*/
public function process_form_assets( $styles, $scripts ) {
foreach ( $scripts as $script_args ) {
if ( ! is_array( $script_args ) ) {
$script_args = array( $script_args );
}
call_user_func_array( 'wp_enqueue_script', $script_args );
}
$this->process_styles( $styles );
}
private function process_styles( $styles ) {
foreach( $styles as $key => $style_args ) {
if ( ! is_numeric( $key ) ) {
$group = $key;
if ( array_key_exists( $group, self::$groups ) ) {
$items = wp_list_pluck( $style_args, 0 );
self::$groups[ $group ] = array_merge( self::$groups[ $group ], $items );
}
$this->process_styles( $style_args );
continue;
}
if ( ! is_array( $style_args ) ) {
$style_args = array( $style_args );
}
call_user_func_array( 'wp_enqueue_style', $style_args );
}
}
}

View File

@@ -1,136 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines;
/**
* Handles outputting CSS blocks composed of custom CSS Properties.
*
* @since 2.7
*/
class Form_CSS_Properties_Output_Engine extends Output_Engine {
private static $processed = 0;
private static $processed_tracker = array();
protected $type = 'form_css_properties';
protected $properties_cb;
public static function get_processed_num() {
return self::$processed;
}
/**
* Set the callback for parsing form properties.
*
* @since 2.7
*
* @param array $properties_cb
*/
public function set_form_css_properties_cb( array $properties_cb ) {
$this->properties_cb = $properties_cb;
}
/**
* Handle outputting the CSS blocks.
*
* @since 2.7
*
* @return void
*/
public function output() {
$self = $this;
add_filter( 'gform_form_after_open', function ( $markup, $form ) use ( $self ) {
$props_block = $self->generate_props_block( $form['id'], $form );
$processed_hash = md5( json_encode( $form ) );
if ( ! in_array( $processed_hash, self::$processed_tracker ) ) {
self::$processed++;
self::$processed_tracker[] = $processed_hash;
}
return $markup . $props_block;
}, 999, 2 );
// Confirmations get processed too early to inject the script tag; inject via regex after render instead.
add_filter( 'gform_get_form_confirmation_filter', function( $markup, $form ) use ( $self ) {
$custom_selector = sprintf( '<style>#gform_confirmation_wrapper_%d.gform-theme{', $form['id'] );
$props_block = $self->generate_props_block( $form['id'], $form, $custom_selector );
$processed_hash = md5( json_encode( $form ) );
if ( ! in_array( $processed_hash, self::$processed_tracker ) ) {
self::$processed++;
self::$processed_tracker[] = $processed_hash;
}
return preg_replace( '/gform_confirmation_wrapper[^<]*/', '$0 ' . $props_block, $markup );
}, 999, 2 );
}
/**
* Generate the properties block for the given form ID>
*
* @since 2.7
*
* @param $form_id
* @param $form
*
* @return string
*/
public function generate_props_block( $form_id, $form, $custom_selector = false ) {
$settings = $this->get_settings( $form_id );
$page_instance = isset( $form['page_instance'] ) ? $form['page_instance'] : 0;
// Get the settings from the block, if they exist.
$all_block_settings = apply_filters( 'gform_form_block_attribute_values', array() );
$block_settings = isset( $all_block_settings[ $form_id ][ $page_instance ] ) ? $all_block_settings[ $form_id ][ $page_instance ] : array();
// Get the settings from the shortcode attribute or form properties, if they exist.
$form_style = $this->parse_form_style( $form );
// Merge the settings - block styles get priority.
$style_settings = ! empty( $block_settings ) ? array_merge( $form_style, $block_settings ) : $form_style;
if ( ! rgar( $style_settings, 'theme' ) || '' == $style_settings['theme'] ) {
$style_settings['theme'] = get_option( 'rg_gforms_default_theme', 'orbital' );
}
$properties = call_user_func_array( $this->properties_cb, array( $form_id, $settings, $style_settings, $form ) );
$properties = array_filter( $properties, function ( $property ) {
if ( ! empty( $property ) ) {
return true;
}
if ( $property === 0 || $property === '0' ) {
return true;
}
return false;
} );
if ( empty( $properties ) ) {
return '';
}
if ( $custom_selector ) {
$props_block = $custom_selector;
} else {
$props_block = sprintf( '<style>#gform_wrapper_%d[data-form-index="%d"].gform-theme,[data-parent-form="%d_%d"]{', $form_id, $page_instance, $form_id, $page_instance );
}
foreach ( $properties as $rule => $property ) {
if ( is_null( $property ) ) {
continue;
}
$props_block .= sprintf( '--%s: %s;', $rule, $property );
}
$props_block .= '}</style>';
return $props_block;
}
}

View File

@@ -1,117 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines;
use GFFormDisplay;
/**
* Output_Engines are responsible for outputting some sort of value, whether CSS blocks,
* markup, or some other theme-layer-related data.
*
* @since 2.7
*/
abstract class Output_Engine {
protected $type;
protected $namespace;
/**
* The namespace of the theme layer, passed from the Addon.
*
* @since 2.7
*
* @param $namespace
*/
public function __construct( $namespace ) {
$this->namespace = $namespace;
}
/**
* Handle output.
*
* @since 2.7
*
* @return void
*/
abstract public function output();
/**
* Getter for type.
*
* @since 2.7
*
* @return string
*/
public function type() {
return $this->type;
}
/**
* Get the settings stored for this theme layer.
*
* @since 2.7
*
* @param $form_id
*
* @return array|mixed
*/
public function get_settings( $form_id ) {
$form = \GFAPI::get_form( $form_id );
return isset( $form[ $this->namespace ] ) ? $form[ $this->namespace ] : array();
}
/**
* Get a specific setting for this theme layer.
*
* @since 2.7
*
* @param $key
* @param $form_id
* @param null $default
*
* @return mixed|null
*/
public function get_setting( $key, $form_id, $default = null ) {
$settings = $this->get_settings( $form_id );
return isset( $settings[ $key ] ) ? $settings[ $key ] : $default;
}
public function get_block_settings( $form_id, $instance = 0 ) {
$block_settings = apply_filters( 'gform_form_block_attribute_values', array() );
return empty( $block_settings[ $form_id ] ) ? array() : rgar( $block_settings[ $form_id ], $instance, array() );
}
/**
* Parse the settings from the style filter or shortcode attributes.
*
* @since 2.7.15
*
* @param $form
*
* @return array
*/
public function parse_form_style( $form ) {
$style_settings = array(
'formId' => $form['id'],
);
if ( rgar( $form, 'theme' ) ) {
$style_settings['theme'] = $form['theme'];
}
if ( rgar( $form, 'styles' ) ) {
$styles = GFFormDisplay::validate_form_styles( $form['styles'] );
foreach( $styles as $key => $value ) {
$style_settings[ $key ] = $value;
}
}
return $style_settings;
}
}

View File

@@ -1,143 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines;
/**
* Engine to provide PHP Markup overrides for given views. Uses gform_field_content and gform_field_content
* to filter the markup and apply the values passed from a custom View class.
*
* @since 2.7
*/
class PHP_Markup_Output_Engine extends Output_Engine {
protected $type = 'php_markup';
protected $views = array();
/**
* Set the views for this engine.
*
* @since 2.7
*
* @param array $views
*
* @return void
*/
public function set_views( array $views ) {
$this->views = $views;
}
/**
* Handle the PHP Markup output by adding filters where necessary.
*
* @since 2.7
*
* @return void
*/
public function output() {
$views = $this->views;
// Form is a special case, add the filter for it here.
if ( isset( $views['form'] ) ) {
add_filter( 'gform_get_form_filter', array( $this, 'handle_form_override' ), 999, 2 );
add_filter( 'gform_get_form_save_confirmation_filter', array( $this, 'handle_form_override' ), 999, 2 );
add_filter( 'gform_get_form_confirmation_filter', array( $this, 'handle_form_override' ), 999, 2 );
add_filter( 'gform_get_form_save_email_confirmation_filter', array( $this, 'handle_form_override' ), 999, 2 );
}
if ( isset( $views['confirmation'] ) ) {
add_filter( 'gform_get_form_confirmation_filter', array( $this, 'handle_confirmation_override' ), 999, 2 );
}
// Add a filter for field output.
add_filter( 'gform_field_content', array( $this, 'handle_field_override' ), 999, 5 );
}
/**
* Handle the PHP Markup output for Forms.
*
* @since 2.7
*
* @hook gform_get_form_filter 999 2
* @hook gform_get_form_save_confirmation_filter 999 2
*
* @return string
*/
public function handle_form_override( $form_string, $form ) {
$page_instance = rgar( $form, 'page_instance', 0 );
$form_view = new $this->views['form']( $this );
$block_settings = $this->get_block_settings( $form['id'], $page_instance );
if ( ! $form_view->should_override( null, $form['id'], $block_settings ) ) {
return $form_string;
}
return $form_view->get_markup( $form_string, $form, null, null, $form['id'] );
}
/**
* Handle the PHP Markup output for Confirmations.
*
* @since 2.7
*
* @hook gform_get_form_save_confirmation_filter 999 2
*
* @return string
*/
public function handle_confirmation_override( $confirmation_string, $form ) {
$page_instance = rgar( $form, 'page_instance', 0 );
$conf_view = new $this->views['confirmation']( $this );
$block_settings = $this->get_block_settings( $form['id'], $page_instance );
if ( ! $conf_view->should_override( null, $form['id'], $block_settings ) ) {
return $confirmation_string;
}
return $conf_view->get_markup( $confirmation_string, $form, null, null, $form['id'] );
}
/**
* Handle the PHP Markup output for specific fields.
*
* @since 2.7
*
* @hook gform_field_content 999 5
*
* @return string
*/
public function handle_field_override( $field_content, $field, $value, $lead_id, $form_id ) {
if ( array_key_exists( 'all', $this->views ) ) {
$field_content = $this->maybe_override_all_fields( $field_content, $field, $value, $lead_id, $form_id );
}
if ( ! array_key_exists( $field->type, $this->views ) ) {
return $field_content;
}
$view = new $this->views[ $field->type ]( $this );
if ( ! $view->should_override( $field, $form_id ) ) {
return $field_content;
}
return $view->get_markup( $field_content, $field, $value, $lead_id, $form_id );
}
/**
* Handle the PHP Markup output if markup is being changed for all fields.
*
* @since 2.7
*
* @return string
*/
private function maybe_override_all_fields( $field_content, $field, $value, $lead_id, $form_id ) {
$view = new $this->views['all']( $this );
if ( ! $view->should_override( $field, $form_id ) ) {
return $field_content;
}
return $view->get_markup( $field_content, $field, $value, $lead_id, $form_id );
}
}

View File

@@ -1,49 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines\Block_Settings_Definition_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Definition_Engines\Settings_Definition_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
/**
* Factory to generate the Definition Engines used by a theme layer.
*
* @since 2.7
*/
class Definition_Engine_Factory {
/**
* Map of engines this factory can provide.
*
* @since 2.7
*
* @return string[]
*/
public function engines() {
return array(
GF_Theme_Layers_Provider::SETTINGS_DEFINITION_ENGINE => Settings_Definition_Engine::class,
GF_Theme_Layers_Provider::BLOCK_SETTINGS_DEFINITION_ENGINE => Block_Settings_Definition_Engine::class,
);
}
/**
* Return a specific engine by name.
*
* @since 2.7
*
* @param $name
*
* @return mixed|null
*/
public function get( $name ) {
$engines = $this->engines();
if ( ! isset( $engines[ $name ] ) ) {
return null;
}
return new $engines[ $name ]();
}
}

View File

@@ -1,66 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Factories;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines\Asset_Enqueue_Output_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines\Form_CSS_Properties_Output_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Engines\Output_Engines\PHP_Markup_Output_Engine;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
/**
* Factory to generate the Output Engines used by a theme layer.
*
* @since 2.7
*/
class Output_Engine_Factory {
protected $namespace;
/**
* Constructor
*
* @since 2.7
*
* @param $namespace The theme layer namespace.
*
* @return void
*/
public function __construct( $namespace ) {
$this->namespace = $namespace;
}
/**
* Map of engines this factory can provide.
*
* @since 2.7
*
* @return string[]
*/
public function engines() {
return array(
GF_Theme_Layers_Provider::MARKUP_OUTPUT_ENGINE => PHP_Markup_Output_Engine::class,
GF_Theme_Layers_Provider::FORM_CSS_PROPERTIES_OUTPUT_ENGINE => Form_CSS_Properties_Output_Engine::class,
GF_Theme_Layers_Provider::ASSET_ENQUEUE_OUTPUT_ENGINE => Asset_Enqueue_Output_Engine::class,
);
}
/**
* Return a specific engine by name.
*
* @since 2.7
*
* @param $name
*
* @return mixed|null
*/
public function get( $name ) {
$engines = $this->engines();
if ( ! isset( $engines[ $name ] ) ) {
return null;
}
return new $engines[ $name ]( $this->namespace );
}
}

View File

@@ -1,54 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
trait Enqueues_Assets {
/**
* Provides an array of scripts to be enqueued for the form.
*
* @since 2.7
*
* @param $form The Form being processed.
* @param $ajax Whether this is an AJAX request.
* @param $settings The current settings for this form.
* @param $block_settings The current block settings for this form.
*
* @return array
*/
abstract public function scripts( $form, $ajax, $settings, $block_settings = array() );
/**
* Provides an array of styles to be enqueued for the form.
*
* @since 2.7
*
* @param $form The Form being processed.
* @param $ajax Whether this is an AJAX request.
* @param $settings The current settings for this form.
* @param $block_settings The current block settings for this form.
*
* @return array
*/
abstract public function styles( $form, $ajax, $settings, $block_settings = array() );
/**
* Add the engine.
*
* @since 2.7
*
* @return void
*/
public function add_engine_asset_enqueues() {
$engine = $this->output_engine_factory->get( GF_Theme_Layers_Provider::ASSET_ENQUEUE_OUTPUT_ENGINE );
$engine->set_styles( array( $this, 'styles' ) );
$engine->set_scripts( array( $this, 'scripts' ) );
$this->output_engines[] = $engine;
add_action( 'init', array( $engine, 'output' ), 11 );
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
trait Has_Block_Settings {
/**
* Returns an array of settings to add to the block.
*
* @since 2.7
*
* @return array
*/
abstract public function block_settings();
/**
* Add the engine.
*
* @since 2.7
*
* @return void
*/
public function add_engine_block_settings() {
$engine = $this->definition_engine_factory->get( GF_Theme_Layers_Provider::BLOCK_SETTINGS_DEFINITION_ENGINE );
$engine->set_block_settings( $this->block_settings() );
$this->definition_engines[] = $engine;
add_filter( 'gform_form_block_attributes', function( $attributes ) use ( $engine ) {
$defined_attrs = $engine->get_definitions();
return array_merge( $attributes, $defined_attrs );
}, 10, 1 );
}
}

View File

@@ -1,32 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
trait Has_Settings_Fields {
/**
* Return an array of settings fields to add for this theme layer.
*
* @since 2.7
*
* @return array
*/
abstract public function settings_fields();
/**
* Add the engine.
*
* @since 2.7
*
* @return void
*/
public function add_engine_settings_field() {
$engine = $this->definition_engine_factory->get( GF_Theme_Layers_Provider::SETTINGS_DEFINITION_ENGINE );
$engine->set_fields( $this->settings_fields() );
$this->definition_engines[] = $engine;
}
}

View File

@@ -1,34 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
trait Modifies_Markup {
/**
* Return an array of views to override for fields/forms.
*
* @since 2.7
*
* @return array
*/
abstract public function overriden_fields();
/**
* Add the engine.
*
* @since 2.7
*
* @return void
*/
public function add_engine_markup_output() {
$engine = $this->output_engine_factory->get( GF_Theme_Layers_Provider::MARKUP_OUTPUT_ENGINE );
$engine->set_views( $this->overriden_fields() );
$this->output_engines[] = $engine;
add_action( 'init', array( $engine, 'output' ), 11 );
}
}

View File

@@ -1,41 +0,0 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Theme_Layers\Framework\Traits;
use Gravity_Forms\Gravity_Forms\Theme_Layers\GF_Theme_Layers_Provider;
/**
* Provides methods for outputting custom CSS Properties for a form.
*
* @since 2.7
*/
trait Outputs_Form_CSS_Properties {
/**
* Return an array of key/value pairs for CSS output.
*
* @since 2.7
*
* @param $form_id The ID of the form being processed.
*
* @return array
*/
abstract public function form_css_properties( $form_id );
/**
* Add the engine.
*
* @since 2.7
*
* @return void
*/
public function add_engine_form_css_properties() {
$engine = $this->output_engine_factory->get( GF_Theme_Layers_Provider::FORM_CSS_PROPERTIES_OUTPUT_ENGINE );
$engine->set_form_css_properties_cb( array( $this, 'form_css_properties' ) );
$this->output_engines[] = $engine;
add_action( 'init', array( $engine, 'output' ), 11 );
}
}