This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,28 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Blocks;
/**
* Gravity Forms Block Attributes class.
*
* @since 2.7.4
*
* Class GF_Block_Attributes
*/
class GF_Block_Attributes {
public function store( $attributes ) {
add_filter( 'gform_form_block_attribute_values', function( $attr ) use ( $attributes ) {
$form_id = rgar( $attributes, 'formId', 0 );
if ( ! array_key_exists( $form_id, $attr ) ) {
$attr[ $form_id ] = array();
}
$attr[ $form_id ][] = $attributes;
return $attr;
} );
}
}
@@ -0,0 +1,320 @@
<?php
// If Gravity Forms Block Manager is not available, do not run.
if ( ! class_exists( 'GF_Blocks' ) || ! defined( 'ABSPATH' ) ) {
exit;
}
class GF_Block_Form extends GF_Block {
/**
* Contains an instance of this block, if available.
*
* @since 2.4.10
* @var GF_Block $_instance If available, contains an instance of this block.
*/
private static $_instance = null;
/**
* Block type.
*
* @since 2.4.10
* @var string
*/
public $type = 'gravityforms/form';
/**
* Handle of primary block script.
*
* @since 2.4.10
* @var string
*/
public $script_handle = 'gform_editor_block_form';
/**
* Handle of primary block style.
*
* @since 2.5.6
* @var string
*/
public $style_handle = 'gform_editor_block_form';
public function __construct() {
$this->assign_attributes();
}
/**
* Register block type and add filters specific to the form block.
*
* @since 2.10.5
*
* @return void
*/
public function init() {
parent::init();
// Move WordPress's custom CSS classes from the <script> to the <div class="gform_wrapper">, so that the form is styled correctly.
add_filter( 'render_block_gravityforms/form', array( $this, 'fix_custom_css_class_placement' ), 10, 2 );
}
private function assign_attributes() {
$default_attributes = GFForms::get_service_container()->get( \Gravity_Forms\Gravity_Forms\Blocks\GF_Blocks_Service_Provider::FORM_BLOCK_ATTRIBUTES );
$attributes = apply_filters( 'gform_form_block_attributes', $default_attributes );
array_walk( $attributes, function ( &$value ) {
$value = array( 'type' => $value['type'] );
} );
$this->attributes = $attributes;
}
/**
* Get instance of this class.
*
* @since 2.4.10
*
* @return GF_Block_Form
*/
public static function get_instance() {
if ( null === self::$_instance ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Move the WordPress "Custom CSS" block-support classes from a leading <script> to the gform_wrapper <div>.
*
* The block "Custom CSS" setting introduced in WP 7.0 adds custom CSS classes to the first HTML element in a block,
* which might be the <script> tag added by GFForms::maybe_prepend_hooks_js_script() instead of the <div class="gform_wrapper">.
* This filter corrects that.
*
* @since 2.10.5
*
* @param string $block_content The rendered block HTML.
* @param array $block The parsed block data.
*
* @return string The (possibly corrected) block HTML.
*/
public function fix_custom_css_class_placement( $block_content, $block ) {
if ( ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
return $block_content;
}
$tags = new WP_HTML_Tag_Processor( $block_content );
// Advance to the first tag. If the content is empty or has no tags, bail.
if ( ! $tags->next_tag() ) {
return $block_content;
}
// Only act when the first element is a <script> — i.e. the hooks JS was prepended.
if ( 'SCRIPT' !== $tags->get_tag() ) {
return $block_content;
}
// Only act when WordPress has placed the custom-CSS marker classes on this <script>.
$class_attr = $tags->get_attribute( 'class' );
if ( ! $class_attr || false === strpos( $class_attr, 'has-custom-css' ) ) {
return $block_content;
}
// Extract the unique `wp-custom-css-*` class generated for this block instance.
$custom_css_class = null;
foreach ( preg_split( '/\s+/', $class_attr ) as $class ) {
if ( 0 === strpos( $class, 'wp-custom-css-' ) ) {
$custom_css_class = $class;
break;
}
}
// Remove the custom-CSS classes from the <script> tag.
$tags->remove_class( 'has-custom-css' );
if ( $custom_css_class ) {
$tags->remove_class( $custom_css_class );
}
// Find the form wrapper <div> and add the classes to it instead.
// next_tag() searches forward from the current cursor position.
if ( $tags->next_tag( array( 'class_name' => 'gform_wrapper' ) ) ) {
$tags->add_class( 'has-custom-css' );
if ( $custom_css_class ) {
$tags->add_class( $custom_css_class );
}
}
return $tags->get_updated_html();
}
// # SCRIPT / STYLES -----------------------------------------------------------------------------------------------
public function register_block_assets() {
parent::register_block_assets();
if ( function_exists( 'wp_enqueue_block_style' ) && is_admin() ) {
wp_enqueue_block_style( $this->type, array( 'handle' => 'gravity_forms_theme_reset' ) );
wp_enqueue_block_style( $this->type, array( 'handle' => 'gravity_forms_theme_foundation' ) );
wp_enqueue_block_style( $this->type, array( 'handle' => 'gravity_forms_theme_framework' ) );
wp_enqueue_block_style( $this->type, array( 'handle' => 'gravity_forms_orbital_theme' ) );
}
}
/**
* Register scripts for block.
*
* @since 2.4.10
*
* @return array
*/
public function scripts() {
return array();
}
/**
* Localize Form block script.
*
* @since 2.4.10
*
* @param array $script Script arguments.
*/
public function localize_script( $script = array() ) {
wp_localize_script(
$script['handle'],
'gform_block_form',
array(
'adminURL' => admin_url( 'admin.php' ),
'forms' => $this->get_forms(),
'preview' => GFCommon::get_base_url() . '/images/gf_block_preview.svg',
)
);
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( $script['handle'], 'gravityforms', GFCommon::get_base_path() . '/languages' );
}
}
/**
* Register styles for block.
*
* @since 2.4.10
*
* @return array
*/
public function styles() {
// Prepare styling dependencies.
$deps = array( 'wp-edit-blocks' );
// Add Gravity Forms styling if CSS is enabled.
if ( ! GFCommon::is_frontend_default_css_disabled() ) {
$deps = array_merge( $deps, array( 'gforms_reset_css', 'gform_basic', 'gforms_formsmain_css', 'gforms_ready_class_css', 'gforms_browsers_css', 'gform_theme' ) );
/**
* Allows users to disable the main theme.css file from being loaded on the Front End.
*
* @since 2.5-beta-3
*
* @param boolean Whether to disable the theme css.
*/
$disable_theme_css = apply_filters( 'gform_disable_form_theme_css', false );
if ( ! $disable_theme_css ) {
$deps[] = 'gform_theme';
}
}
$dev_min = defined( 'GF_SCRIPT_DEBUG' ) && GF_SCRIPT_DEBUG ? '' : '.min';
return array(
array(
'handle' => $this->style_handle,
'src' => GFCommon::get_base_url() . "/assets/css/dist/blocks{$dev_min}.css",
'deps' => $deps,
'version' => defined( 'GF_SCRIPT_DEBUG' ) && GF_SCRIPT_DEBUG ? filemtime( GFCommon::get_base_path() . "/assets/css/dist/blocks{$dev_min}.css" ) : GFForms::$version,
),
);
}
// # BLOCK RENDER -------------------------------------------------------------------------------------------------
/**
* Display block contents on frontend.
*
* @since 2.4.10
*
* @param array $attributes Block attributes.
*
* @return string
*/
public function render_block( $attributes = array() ) {
GFForms::get_service_container()->get( 'block_attributes' )->store( $attributes );
// Prepare variables.
$form_id = rgar( $attributes, 'formId' ) ? $attributes['formId'] : false;
$title = isset( $attributes['title'] ) ? $attributes['title'] : true;
$description = isset( $attributes['description'] ) ? $attributes['description'] : true;
$ajax = isset( $attributes['ajax'] ) ? $attributes['ajax'] : false;
$tabindex = isset( $attributes['tabindex'] ) ? intval( $attributes['tabindex'] ) : 0;
$field_values = isset( $attributes['fieldValues'] ) ? $attributes['fieldValues'] : '';
// If form ID was not provided or form does not exist, return.
if ( ! $form_id || ( $form_id && ! GFAPI::get_form( $form_id ) ) ) {
return '';
}
// Use Gravity Forms function for REST API requests.
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
// Start output buffering.
ob_start();
// Prepare field values.
if ( ! empty( $field_values ) ) {
$field_values = str_replace( '&#038;', '&', $field_values );
parse_str( $field_values, $field_value_array );
$field_values = stripslashes_deep( $field_value_array );
}
// Get form output string.
$form_string = gravity_form( $form_id, $title, $description, false, $field_values, $ajax, $tabindex, false, rgar( $attributes, 'theme' ), json_encode( $attributes ) );
// Get output buffer contents.
$buffer_contents = ob_get_contents();
ob_end_clean();
// Return buffer contents with form string.
return $buffer_contents . $form_string; // nosemgrep audit.php.wp.security.xss.block-attr
}
// Encode field values.
$field_values = htmlspecialchars_decode( $field_values );
$field_values = str_replace( array( '&#038;', '&#091;', '&#093;' ), array( '&', '[', ']' ), $field_values );
parse_str( $field_values, $field_value_array ); //parsing query string like string for field values and placing them into an associative array
$field_values = stripslashes_deep( $field_value_array );
// If no field values are set, set field values to an empty string
if ( empty( $field_values ) ) {
$field_values = '';
}
return gravity_form( $form_id, $title, $description, false, $field_values, $ajax, $tabindex, false, rgar( $attributes, 'theme' ), json_encode( $attributes ) ); // nosemgrep audit.php.wp.security.xss.block-attr
}
}
// Register block.
if ( true !== ( $registered = GF_Blocks::register( GF_Block_Form::get_instance() ) ) && is_wp_error( $registered ) ) {
// Log that block could not be registered.
GFCommon::log_error( 'Unable to register block; ' . $registered->get_error_message() );
}
@@ -0,0 +1,375 @@
<?php
// If Gravity Forms Block Manager is not available, do not run.
if ( ! class_exists( 'GF_Blocks' ) || ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Base Gravity Forms Block class.
*
* @since 2.4.10
*
* Class GF_Block
*/
class GF_Block {
/**
* Contains an instance of this block, if available.
*
* @since 2.4.10
* @var GF_Block $_instance If available, contains an instance of this block.
*/
private static $_instance = null;
/**
* Block type.
*
* @since 2.4.10
* @var string
*/
public $type = '';
/**
* Handle of primary block editor script.
*
* @since 2.4.10
* @var string
*/
public $script_handle = '';
/**
* Handle of primary block editor style.
*
* @since 2.5.6
* @var string
*/
public $style_handle = '';
/**
* Handle of primary block FE script.
*
* @since 2.4.10
* @var string
*/
public $fe_script_handle = '';
/**
* Handle of primary block FE style.
*
* @since 2.5.6
* @var string
*/
public $fe_style_handle = '';
/**
* Block attributes.
*
* @since 2.4.10
* @var array
*/
public $attributes = array();
/**
* Register block type.
* Enqueue editor assets.
*
* @since 2.4.10
*
* @uses GF_Block::register_block_type()
*/
public function init() {
$this->register_block_type();
$this->register_block_assets();
add_action( 'gform_post_enqueue_scripts', array( $this, 'post_enqueue_scripts' ), 10, 3 );
}
// # BLOCK REGISTRATION --------------------------------------------------------------------------------------------
/**
* Get block type.
*
* @since 2.4.10
*
* @return string
*/
public function get_type() {
return $this->type;
}
/**
* Register block with WordPress.
*
* @since 2.4.10
*/
public function register_block_type() {
register_block_type( $this->get_type(), $this->get_block_properties() );
}
/**
* Get an array representing the properties for this block. Can be overriden by inheriting
* classes in order to provide more/fewer/different properties.
*
* @since 2.5.6
*
* @return array
*/
protected function get_block_properties() {
return array(
'render_callback' => array( $this, 'render_block' ),
'editor_script' => $this->script_handle,
'editor_style' => $this->style_handle,
'attributes' => $this->attributes,
'script' => $this->fe_script_handle,
'style' => $this->fe_style_handle,
);
}
/**
* Enqueue/register the block's assets upon init
*
* @since 2.5.6
*
* @return void
*/
public function register_block_assets() {
add_action( 'enqueue_block_assets', array( $this, 'register_scripts' ) );
add_action( 'enqueue_block_assets', array( $this, 'register_styles' ) );
}
/**
* Checks allowed blocks for Gravity forms blocks to only enqueue block editor assets when necessary.
*
* @since 2.4.18
*
* @deprecated since 2.5.6. See GF_Block::register_block_assets()
*
* @param bool|array $allowed_block_types Array of block type slugs, or boolean to enable/disable all.
*
* @return bool|array
*/
public function check_allowed_blocks( $allowed_block_types ) {
// Only enqueue block editor assets if all blocks are allowed or if the current block type is an allowed block.
if ( $allowed_block_types === true || ( is_array( $allowed_block_types ) && in_array( $this->get_type(), $allowed_block_types ) ) ) {
add_action( 'enqueue_block_assets', array( $this, 'register_scripts' ) );
add_action( 'enqueue_block_assets', array( $this, 'register_styles' ) );
}
return $allowed_block_types;
}
// # SCRIPT ENQUEUEING ---------------------------------------------------------------------------------------------
/**
* Enqueue block scripts.
*
* @since 2.4.10
*
* @uses GF_Block::scripts()
*/
public function register_scripts() {
if ( ! is_admin() ) {
return;
}
// Get registered scripts.
$scripts = $this->scripts();
// If no scripts are registered, return.
if ( empty( $scripts ) ) {
return;
}
// Loop through scripts.
foreach ( $scripts as $script ) {
// Prepare parameters.
$src = isset( $script['src'] ) ? $script['src'] : false;
$deps = isset( $script['deps'] ) ? $script['deps'] : array();
$version = isset( $script['version'] ) ? $script['version'] : false;
$in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
// Enqueue script.
if ( $this->script_handle === $script['handle'] ) {
// Support for the editor_style property, if a style_handle is defined. No need to enqueue.
wp_register_script( $script['handle'], $src, $deps, $version, $in_footer );
} else {
// style_handle isn't defined, or this is an additional style. Enqueue it manually.
wp_enqueue_script( $script['handle'], $src, $deps, $version, $in_footer );
}
// Localize script.
if ( rgar( $script, 'strings' ) ) {
wp_localize_script( $script['handle'], $script['handle'] . '_strings', $script['strings'] );
}
// Run script callback.
if ( rgar( $script, 'callback' ) && is_callable( $script['callback'] ) ) {
call_user_func( $script['callback'], $script );
}
}
}
/**
* Enqueue scripts
*
* @depecated since 2.5.6. Use ::register_scripts() instead.
*
* @return void
*/
public function enqueue_scripts() {
$this->register_scripts();
}
/**
* Override this function to provide a list of scripts to be enqueued.
* Following is an example of the array that is expected to be returned by this function:
* <pre>
* <code>
*
* array(
* array(
* 'handle' => 'super_signature_script',
* 'src' => $this->get_base_url() . '/super_signature/ss.js',
* 'version' => $this->_version,
* 'deps' => array( 'jquery'),
* 'callback' => array( $this, 'localize_scripts' ),
* 'strings' => array(
* // Accessible in JavaScript using the global variable "[script handle]_strings"
* 'stringKey1' => __( 'The string', 'gravityforms' ),
* 'stringKey2' => __( 'Another string.', 'gravityforms' )
* )
* )
* );
*
* </code>
* </pre>
*
* @since 2.4.10
*
* @return array
*/
public function scripts() {
return array();
}
// # STYLE ENQUEUEING ----------------------------------------------------------------------------------------------
/**
* Enqueue block styles.
*
* @since 2.4.10
*/
public function register_styles() {
if ( ! is_admin() ) {
return;
}
// Get registered styles.
$styles = $this->styles();
// If no styles are registered, return.
if ( empty( $styles ) ) {
return;
}
// Loop through styles.
foreach ( $styles as $style ) {
// Prepare parameters.
$src = isset( $style['src'] ) ? $style['src'] : false;
$deps = isset( $style['deps'] ) ? $style['deps'] : array();
$version = isset( $style['version'] ) ? $style['version'] : false;
$media = isset( $style['media'] ) ? $style['media'] : 'all';
if ( $this->style_handle === $style['handle'] ) {
// Support for the editor_style property, if a style_handle is defined. No need to enqueue.
wp_register_style( $style['handle'], $src, $deps, $version, $media );
} else {
// style_handle isn't defined, or this is an additional style. Enqueue it manually.
wp_enqueue_style( $style['handle'], $src, $deps, $version, $media );
}
}
}
/**
* Enqueue styles
*
* @depecated since 2.5.6. Use ::register_styles() instead.
*
* @return void
*/
public function enqueue_styles() {
$this->register_styles();
}
/**
* Override this function to provide a list of styles to be enqueued.
* See scripts() for an example of the format expected to be returned.
*
* @since 2.4.10
*
* @return array
*/
public function styles() {
return array();
}
// # BLOCK RENDER -------------------------------------------------------------------------------------------------
/**
* Display block contents on frontend.
*
* @since 2.4.10
*
* @param array $attributes Block attributes.
*
* @return string
*/
public function render_block( $attributes = array() ) {
return '';
}
/**
* Override to perform additional actions when scripts/styles are enqueued on the wp_enqueue_scripts hook.
*
* @since 2.4.18
*
* @param array $found_forms An array of found forms using the form ID as the key to the ajax status.
* @param array $found_blocks An array of found GF blocks.
* @param WP_Post $post The post which was processed.
*/
public function post_enqueue_scripts( $found_forms, $found_blocks, $post ) {
}
}
@@ -0,0 +1,245 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Blocks;
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Service_Provider;
use Gravity_Forms\Gravity_Forms\Blocks\Config\GF_Blocks_Config;
use Gravity_Forms\Gravity_Forms\Blocks\GF_Block_Attributes;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
use GFFormDisplay;
use GFCommon;
/**
* Class GF_Blocks_Service_Provider
*
* Service provider for the Blocks Service.
*
* @package Gravity_Forms\Gravity_Forms\Blocks;
*/
class GF_Blocks_Service_Provider extends GF_Service_Provider {
// Configs
const BLOCKS_CONFIG = 'blocks_config';
// Attributes
const FORM_BLOCK_ATTRIBUTES = 'form_block_attributes';
const BLOCK_ATTRIBUTES = 'block_attributes';
/**
* Array mapping config class names to their container ID.
*
* @since
*
* @var string[]
*/
protected $configs = array(
self::BLOCKS_CONFIG => GF_Blocks_Config::class,
);
/**
* Register services to the container.
*
* @since
*
* @param GF_Service_Container $container
*/
public function register( GF_Service_Container $container ) {
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-block-attributes.php' );
require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-blocks-config.php' );
$container->add( self::FORM_BLOCK_ATTRIBUTES, function () {
require_once( GFCommon::get_base_path() . '/form_display.php' );
$global_styles = GFFormDisplay::validate_form_styles( apply_filters( 'gform_default_styles', false ) );
return array(
'formId' =>
array(
'type' => 'string',
),
'title' =>
array(
'type' => 'boolean',
'default' => true,
),
'description' =>
array(
'type' => 'boolean',
'default' => true,
),
'ajax' =>
array(
'type' => 'boolean',
'default' => false,
),
'tabindex' =>
array(
'type' => 'string',
),
'fieldValues' =>
array(
'type' => 'string',
),
'formPreview' =>
array(
'type' => 'boolean',
'default' => true,
),
'imgPreview' =>
array(
'type' => 'boolean',
'default' => false,
),
'theme' =>
array(
'type' => 'string',
'default' => '',
),
'inputSize' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputSize' ) ? $global_styles['inputSize'] : 'md',
),
'inputBorderRadius' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputBorderRadius' ) ? $global_styles['inputBorderRadius'] : 3,
),
'inputBorderColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputBorderColor' ) ? $global_styles['inputBorderColor'] : '#686e77',
),
'inputBackgroundColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputBackgroundColor' ) ? $global_styles['inputBackgroundColor'] : '#fff',
),
'inputColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputColor' ) ? $global_styles['inputColor'] : '#112337',
),
'inputPrimaryColor' =>
array(
'type' => 'string',
// Setting this to empty allows us to set this to what the appropriate default
// should be from within the block. When empty, it defaults to:
// buttonPrimaryBackgroundColor
'default' => rgar( $global_styles, 'inputPrimaryColor' ) ? $global_styles['inputPrimaryColor'] : '', // #204ce5
),
'inputImageChoiceAppearance' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputImageChoiceAppearance' ) ? $global_styles['inputImageChoiceAppearance'] : 'card',
),
'inputImageChoiceStyle' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputImageChoiceStyle' ) ? $global_styles['inputImageChoiceStyle'] : 'square',
),
'inputImageChoiceSize' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'inputImageChoiceSize' ) ? $global_styles['inputImageChoiceSize'] : 'md',
),
'labelFontSize' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'labelFontSize' ) ? $global_styles['labelFontSize'] : 14,
),
'labelColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'labelColor' ) ? $global_styles['labelColor'] : '#112337',
),
'descriptionFontSize' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'descriptionFontSize' ) ? $global_styles['descriptionFontSize'] : 13,
),
'descriptionColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'descriptionColor' ) ? $global_styles['descriptionColor'] : '#585e6a',
),
'buttonPrimaryBackgroundColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'buttonPrimaryBackgroundColor' ) ? $global_styles['buttonPrimaryBackgroundColor'] : '#204ce5',
),
'buttonPrimaryColor' =>
array(
'type' => 'string',
'default' => rgar( $global_styles, 'buttonPrimaryColor' ) ? $global_styles['buttonPrimaryColor'] : '#fff',
),
);
} );
$this->add_configs( $container );
$this->block_attributes( $container );
}
/**
* Initialize any actions or hooks.
*
* @since
*
* @param GF_Service_Container $container
*
* @return void
*/
public function init( GF_Service_Container $container ) {
add_action( 'gform_post_enqueue_scripts', function( $found_forms, $found_blocks, $post ) use ( $container ) {
foreach( $found_blocks as $block ) {
$attributes = $block['attrs'];
$container->get( self::BLOCK_ATTRIBUTES )->store( $attributes );
}
}, -10, 3 );
}
/**
* For each config defined in $configs, instantiate and add to container.
*
* @since
*
* @param GF_Service_Container $container
*
* @return void
*/
private function add_configs( GF_Service_Container $container ) {
foreach ( $this->configs as $name => $class ) {
$container->add( $name, function () use ( $container, $class ) {
if ( $class == GF_Blocks_Config::class ) {
return new $class( $container->get( GF_Config_Service_Provider::DATA_PARSER ), $container->get( self::FORM_BLOCK_ATTRIBUTES ) );
}
return new $class( $container->get( GF_Config_Service_Provider::DATA_PARSER ) );
} );
$container->get( GF_Config_Service_Provider::CONFIG_COLLECTION )->add_config( $container->get( $name ) );
}
}
/**
* Register Block services.
*
* @since 2.7.4
*
* @param GF_Service_Container $container
*
* @return void
*/
private function block_attributes( GF_Service_Container $container ) {
$container->add( self::BLOCK_ATTRIBUTES, function () use ( $container ) {
return new GF_Block_Attributes();
} );
}
}
@@ -0,0 +1,89 @@
<?php
defined( 'ABSPATH' ) or die();
// Load core Block class.
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-block.php' );
/**
* Handles management of Gravity Forms editor blocks.
*
* @since 2.4.10
*
* Class GF_Blocks
*/
class GF_Blocks {
/**
* Registered Gravity Forms editor blocks.
*
* @since 2.4.10
* @var GF_Block[]
*/
private static $_blocks = array();
/**
* Register a block type.
*
* @since 2.4.10
*
* @param GF_Block $block Block class.
*
* @return bool|WP_Error
*/
public static function register( $block ) {
if ( ! is_subclass_of( $block, 'GF_Block' ) ) {
return new WP_Error( 'block_not_subclass', 'Must be a subclass of GF_Block' );
}
// Get block type.
$block_type = $block->get_type();
if ( empty( $block_type ) ) {
return new WP_Error( 'block_type_undefined', 'The type must be set' );
}
if ( isset( self::$_blocks[ $block_type ] ) ) {
return new WP_Error( 'block_already_registered', 'Block type already registered: ' . $block_type );
}
// Register block.
self::$_blocks[ $block_type ] = $block;
// Initialize block.
call_user_func( array( $block, 'init' ) );
return true;
}
/**
* Get instance of block.
*
* @since 2.4.10
*
* @param string $block_type Block type.
*
* @return GF_Block|bool
*/
public static function get( $block_type ) {
return isset( self::$_blocks[ $block_type ] ) ? self::$_blocks[ $block_type ] : false;
}
/**
* Returns an array of registered block types.
*
* @since 2.4.18
*
* @return array
*/
public static function get_all_types() {
return array_keys( self::$_blocks );
}
}
new GF_Blocks();
@@ -0,0 +1,174 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Blocks\Config;
use GFSettings;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Data_Parser;
use \GFCommon;
use \GFAPI;
use \GFFormDisplay;
/**
* Config items for Blocks.
*
* @since
*/
class GF_Blocks_Config extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
protected $attributes = array();
public function __construct( GF_Config_Data_Parser $parser, array $attributes ) {
parent::__construct( $parser );
$this->attributes = $attributes;
}
public function should_enqueue() {
return GFCommon::is_block_editor_page();
}
/**
* Get list of forms for Block control.
*
* @since 2.4.10
*
* @return array
*/
public function get_forms() {
// Initialize forms array.
$forms = array();
// Load GFFormDisplay class.
if ( ! class_exists( 'GFFormDisplay' ) ) {
require_once GFCommon::get_base_path() . '/form_display.php';
}
// Get form objects.
$form_objects = GFAPI::get_forms( true, false, 'title', 'ASC' );
// Loop through forms, add conditional logic check.
foreach ( $form_objects as $form ) {
$forms[] = array(
'id' => $form['id'],
'title' => $form['title'],
'hasConditionalLogic' => GFFormDisplay::has_conditional_logic( $form ),
'isLegacyMarkup' => GFCommon::is_legacy_markup_enabled( $form ),
'hasImageChoices' => GFFormDisplay::has_image_choices( $form ),
);
}
/**
* Modify the list of available forms displayed in the Form block.
*
* @since 2.4.23
*
* @param array $forms A collection of active forms on site.
*/
return apply_filters( 'gform_block_form_forms', $forms );
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
$attributes = apply_filters( 'gform_form_block_attributes', $this->attributes );
$orbital_default = GFSettings::is_orbital_default();
return array(
'block_editor' => array(
'gravityforms/form' => array(
'data' => array(
'attributes' => $attributes,
'adminURL' => admin_url( 'admin.php' ),
'forms' => $this->get_forms(),
'preview' => GFCommon::get_base_url() . '/images/gf_block_preview.svg',
'orbitalDefault' => $orbital_default,
'block_docs_url' => 'https://docs.gravityforms.com/gravity-forms-gutenberg-block/',
'styles' => array(
'defaults' => \GFForms::get_service_container()->get( \Gravity_Forms\Gravity_Forms\Form_Display\GF_Form_Display_Service_Provider::BLOCK_STYLES_DEFAULTS ),
),
),
'i18n' => array(
'accent' => esc_html__( 'Accent', 'gravityforms' ),
'advanced' => esc_html__( 'Advanced', 'gravityforms' ),
'ajax' => esc_html__( 'AJAX', 'gravityforms' ),
'appearance' => esc_html__( 'Appearance', 'gravityforms' ),
'background' => esc_html__( 'Background', 'gravityforms' ),
'border' => esc_html__( 'Border', 'gravityforms' ),
'border_radius' => esc_html__( 'Border Radius', 'gravityforms' ),
'button_styles' => esc_html__( 'Button Styles', 'gravityforms' ),
'cancel' => esc_html__( 'Cancel', 'gravityforms' ),
'card' => esc_html__( 'Card', 'gravityforms' ),
'circle' => esc_html__( 'Circle', 'gravityforms' ),
'close' => esc_html__( 'Close', 'gravityforms' ),
'colors' => esc_html__( 'Colors', 'gravityforms' ),
'copy_and_paste_not_available' => esc_html__( 'Copy / Paste Not Available', 'gravityforms' ),
'copy_and_paste_requires_secure_connection' => esc_html__( 'Copy and paste functionality requires a secure connection. Reload this page using an HTTPS URL and try again.', 'gravityforms' ),
'copy_form_styles' => esc_html__( 'Copy Form Styles', 'gravityforms' ),
'custom_colors' => esc_html__( 'Custom Colors', 'gravityforms' ),
'default_colors' => esc_html__( 'Default Colors', 'gravityforms' ),
'description_styles' => esc_html__( 'Description Styles', 'gravityforms' ),
'edit_form' => esc_html__( 'Edit Form', 'gravityforms' ),
'field_values' => esc_html__( 'Field Values', 'gravityforms' ),
'font_size' => esc_html__( 'Font Size', 'gravityforms' ),
'form' => esc_html__( 'Form', 'gravityforms' ),
'form_id' => esc_html__( 'Form ID: %s', 'gravityforms' ),
'form_settings' => esc_html__( 'Form Settings', 'gravityforms' ),
'form_styles' => esc_html__( 'Form Styles', 'gravityforms' ),
'form_theme' => esc_html__( 'Form Theme', 'gravityforms' ),
'form_style_options_not_available' => esc_html__( 'Form style options are not available for forms that use %1$slegacy mode%2$s.', 'gravityforms' ),
'gravity_forms' => esc_html__( 'Gravity Forms', 'gravityforms' ),
'gravity_forms_25_theme' => esc_html__( 'Gravity Forms 2.5 Theme', 'gravityforms' ),
'image_choice_styles' => esc_html__( 'Image Choice Styles', 'gravityforms' ),
'inherit_from_default' => esc_html__( 'Inherit from default (%s)', 'gravityforms' ),
'input_styles' => esc_html__( 'Input Styles', 'gravityforms' ),
'insert_gform_block_title' => esc_html__( 'Add Block To Page', 'gravityforms' ),
'insert_gform_block_content' => esc_html__( 'Click or drag the Gravity Forms Block into the page to insert the form you selected. %1$sLearn More.%2$s', 'gravityforms' ),
'in_pixels' => esc_html__( 'In pixels.', 'gravityforms' ),
'invalid_form_styles' => esc_html__( 'Invalid Form Styles', 'gravityforms' ),
'learn_more_orbital' => esc_html__( 'Learn more about configuring your form to use Orbital.', 'gravityforms' ),
'label_styles' => esc_html__( 'Label Styles', 'gravityforms' ),
'large' => esc_html__( 'Large', 'gravityforms' ),
'medium' => esc_html__( 'Medium', 'gravityforms' ),
'no_card' => esc_html__( 'No Card', 'gravityforms' ),
'ok' => esc_html__( 'OK', 'gravityforms' ),
'orbital_theme' => esc_html__( 'Orbital Theme', 'gravityforms' ),
'paste_form_styles' => esc_html__( 'Paste Form Styles', 'gravityforms' ),
'paste_not_available' => esc_html__( 'Paste Not Available', 'gravityforms' ),
'please_ensure_correct_format' => esc_html__( 'Please ensure the form styles you are trying to paste are in the correct format.', 'gravityforms' ),
'preview' => esc_html__( 'Preview', 'gravityforms' ),
'reset_defaults' => esc_html__( 'Reset Defaults', 'gravityforms' ),
'restore_defaults' => esc_html__( 'Restore Defaults', 'gravityforms' ),
'restore_default_styles' => esc_html__( 'Restore Default Styles', 'gravityforms' ),
'select_a_form' => esc_html__( 'Select a Form', 'gravityforms' ),
'select_and_display_form' => esc_html__( 'Select and display one of your forms.', 'gravityforms' ),
'show_form_description' => esc_html__( 'Show Form Description', 'gravityforms' ),
'show_form_title' => esc_html__( 'Show Form Title', 'gravityforms' ),
'size' => esc_html__( 'Size', 'gravityforms' ),
'small' => esc_html__( 'Small', 'gravityforms' ),
'style' => esc_html__( 'Style', 'gravityforms' ),
'square' => esc_html__( 'Square', 'gravityforms' ),
'tabindex' => esc_html__( 'Tabindex', 'gravityforms' ),
'text' => esc_html__( 'Text', 'gravityforms' ),
'theme_colors' => esc_html__( 'Theme Colors', 'gravityforms' ),
'the_accent_color_is_used' => esc_html__( 'The accent color is used for aspects such as checkmarks and dropdown choices.', 'gravityforms' ),
'the_background_color_is_used' => esc_html__( 'The background color is used for various form elements, such as buttons and progress bars.', 'gravityforms' ),
'the_selected_form_deleted' => esc_html__( 'The selected form has been deleted or trashed. Please select a new form.', 'gravityforms' ),
'this_will_restore_defaults' => esc_html__( 'This will restore your form styles back to their default values and cannot be undone. Are you sure you want to continue?', 'gravityforms' ),
'you_must_have_one_form' => esc_html__( 'You must have at least one form to use the block.', 'gravityforms' ),
'your_browser_no_permission_to_paste' => __( 'Your browser does not have permission to paste from the clipboard. <p>Please navigate to <strong>about:config</strong> and change the preference <strong>dom.events.asyncClipboard.readText</strong> to <strong>true</strong>.', 'gravityforms' ),
'external_link_opens_in_new_tab' => esc_html__( '(opens in a new tab)', 'gravityforms' ),
),
),
)
);
}
}