plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,145 @@
<?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;
/**
* @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;
}
}

View File

@@ -0,0 +1,45 @@
<?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

@@ -0,0 +1,35 @@
<?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

@@ -0,0 +1,43 @@
<?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

@@ -0,0 +1,200 @@
<?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

@@ -0,0 +1,136 @@
<?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

@@ -0,0 +1,117 @@
<?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

@@ -0,0 +1,143 @@
<?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

@@ -0,0 +1,49 @@
<?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

@@ -0,0 +1,66 @@
<?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

@@ -0,0 +1,54 @@
<?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

@@ -0,0 +1,38 @@
<?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

@@ -0,0 +1,32 @@
<?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

@@ -0,0 +1,34 @@
<?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

@@ -0,0 +1,41 @@
<?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 );
}
}