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,41 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor\Choices_UI\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* I18N items for the Choices UI.
*
* @since 2.6
*/
class GF_Choices_UI_Config_I18N extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'form_editor' => array(
'choices_ui' => array(
'i18n' => array(
'description' => __( 'Define the choices for this field. If the field type supports it you will also be able to select the default choice(s) to the left of the choice.', 'gravityforms' ),
'title' => __( 'Choices', 'gravityforms' ),
'expandableTitle' => __( 'Expand the Choices window', 'gravityforms' ),
),
),
),
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor\Choices_UI\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* Data config items for the Choices UI.
*
* @since 2.6
*/
class GF_Choices_UI_Config extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'form_editor' => array(
'choices_ui' => array(
'data' => array(),
),
),
);
}
}

View File

@@ -0,0 +1,170 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor;
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Service_Provider;
use Gravity_Forms\Gravity_Forms\Form_Editor\Choices_UI\Config\GF_Choices_UI_Config;
use Gravity_Forms\Gravity_Forms\Form_Editor\Choices_UI\Config\GF_Choices_UI_Config_I18N;
use Gravity_Forms\Gravity_Forms\Form_Editor\Save_Form\Config\GF_Form_Editor_Form_Save_Config;
use Gravity_Forms\Gravity_Forms\Form_Editor\Save_Form\Endpoints\GF_Save_Form_Endpoint_Form_Editor;
use Gravity_Forms\Gravity_Forms\Form_Editor\Renderer\GF_Form_Editor_Renderer;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
use Gravity_Forms\Gravity_Forms\Util\GF_Util_Service_Provider;
use Gravity_Forms\Gravity_Forms\Save_Form\GF_Save_Form_Service_Provider;
/**
* Class GF_Embed_Service_Provider
*
* Service provider for the Form Editor Services.
*
* @package Gravity_Forms\Gravity_Forms\Form_Editor;
*/
class GF_Form_Editor_Service_Provider extends GF_Service_Provider {
// Configs
const CHOICES_UI_CONFIG = 'embed_config';
const CHOICES_UI_CONFIG_I18N = 'embed_config_i18n';
const FORM_EDITOR_SAVE_CONFIG = 'form_editor_save_config';
const FORM_EDITOR_RENDERER = 'form_editor_renderer';
/**
* Array mapping config class names to their container ID.
*
* @since 2.6
*
* @var string[]
*/
protected $configs = array(
self::CHOICES_UI_CONFIG => GF_Choices_UI_Config::class,
self::CHOICES_UI_CONFIG_I18N => GF_Choices_UI_Config_I18N::class,
self::FORM_EDITOR_SAVE_CONFIG => GF_Form_Editor_Form_Save_Config::class,
);
// Configs names, used as keys for the configuration classes in the service container.
// Endpoint names, used as keys for the endpoint classes in the service container.
// keys are the same names for the ajax actions.
const ENDPOINT_FORM_EDITOR_SAVE = 'form_editor_save_form';
/**
* The endpoint class names and their corresponding string keys in the service container.
*
* @since 2.6
*
* @var string[]
*/
protected $endpoints = array(
self::ENDPOINT_FORM_EDITOR_SAVE => GF_Save_Form_Endpoint_Form_Editor::class,
);
public function register( GF_Service_Container $container ) {
// Choices UI Configs
require_once( plugin_dir_path( __FILE__ ) . '/choices-ui/config/class-gf-choices-ui-config.php' );
require_once( plugin_dir_path( __FILE__ ) . '/choices-ui/config/class-gf-choices-ui-config-i18n.php' );
// Form Saver Configs
require_once plugin_dir_path( __FILE__ ) . 'save-form/config/class-gf-form-editor-form-save-config.php';
require_once plugin_dir_path( __FILE__ ) . 'save-form/endpoints/class-gf-save-form-endpoint-form-editor.php';
// Editor Renderers.
require_once plugin_dir_path( __FILE__ ) . 'renderer/class-gf-form-editor-renderer.php';
$this->add_configs( $container );
$this->add_endpoints( $container );
$container->add( self::FORM_EDITOR_RENDERER, new GF_Form_Editor_Renderer() );
}
/**
* For each config defined in $configs, instantiate and add to container.
*
* @since 2.6
*
* @param GF_Service_Container $container
*
* @return void
*/
private function add_configs( GF_Service_Container $container ) {
$deps = array(
GF_Config_Service_Provider::DATA_PARSER => $container->get( GF_Config_Service_Provider::DATA_PARSER ),
GF_Util_Service_Provider::GF_FORMS => $container->get( GF_Util_Service_Provider::GF_FORMS ),
GF_Util_Service_Provider::GF_API => $container->get( GF_Util_Service_Provider::GF_API ),
);
foreach ( $this->configs as $name => $class ) {
$container->add(
$name,
function () use ( $container, $class, $deps ) {
return new $class( $container->get( GF_Config_Service_Provider::DATA_PARSER ), $deps );
}
);
$container->get( GF_Config_Service_Provider::CONFIG_COLLECTION )->add_config( $container->get( $name ) );
}
}
/**
* Register Form Saving Endpoints.
*
* @since 2.6
*
* @param GF_Service_Container $container
*
* @return void
*/
private function add_endpoints( GF_Service_Container $container ) {
foreach ( $this->endpoints as $name => $class ) {
$container->add(
$name,
function () use ( $container, $class ) {
return new $class(
array(
GF_Save_Form_Service_Provider::GF_FORM_CRUD_HANDLER => $container->get( GF_Save_Form_Service_Provider::GF_FORM_CRUD_HANDLER ),
GF_Util_Service_Provider::GF_FORMS_MODEL => $container->get( GF_Util_Service_Provider::GF_FORMS_MODEL ),
GF_Util_Service_Provider::GF_FORMS => $container->get( GF_Util_Service_Provider::GF_FORMS ),
)
);
}
);
}
}
/**
* Initialize any actions or hooks required for handling form saving..
*
* @since 2.6
*
* @param GF_Service_Container $container
*/
public function init( GF_Service_Container $container ) {
add_filter(
'gform_is_form_editor',
function ( $is_editor ) {
if ( GF_Save_Form_Endpoint_Form_Editor::ACTION_NAME === rgpost( 'action' ) ) {
return true;
}
return $is_editor;
}
);
add_filter(
'gform_ajax_actions',
function( $ajax_actions ) {
$ajax_actions[] = GF_Save_Form_Endpoint_Form_Editor::ACTION_NAME;
return $ajax_actions;
}
);
add_action(
'wp_ajax_' . GF_Save_Form_Endpoint_Form_Editor::ACTION_NAME,
function () use ( $container ) {
$container->get( self::ENDPOINT_FORM_EDITOR_SAVE )->handle();
}
);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor\Renderer;
class GF_Form_Editor_Renderer {
/**
* Generates the form editor markup by calling the forms_page which runs on page load.
*
* @since 2.6
*
* @param string $form_id The ID of the form to generate form editor markup for.
* @param \GFFormDetail $form_detail An instance of the FormDetail class
* @param boolean $echo Whether to echo the form contents or not. Default false.
*
* @return string
*/
public static function render_form_editor( $form_id, $form_detail, $echo = false ) {
$editor = '';
ob_start();
$form_detail::forms_page( $form_id );
$editor = ob_get_clean();
if ( $echo ) {
echo $editor;
}
return utf8_encode( $editor );
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor\Save_Form\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
use Gravity_Forms\Gravity_Forms\Save_Form\Config\GF_Admin_Form_Save_Config;
use Gravity_Forms\Gravity_Forms\Form_Editor\Save_Form\Endpoints\GF_Save_Form_Endpoint_Form_Editor;
class GF_Form_Editor_Form_Save_Config extends GF_Admin_Form_Save_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
public function data() {
return array(
'form_editor_save_form' => array(
'data' => array(
'selectors' => $this->get_selectors(),
'domEvents' => $this->get_dom_events(),
'animationDelay' => '1000',
'json_containers' => array(
GF_Admin_Form_Save_Config::JSON_START_STRING,
GF_Admin_Form_Save_Config::JSON_END_STRING,
),
'urls' => array(
'formPreview' => trailingslashit( site_url() ) . '?gf_page=preview&id=%s',
),
'registeredAddons' => \GFAddOn::get_registered_addons(),
),
'endpoints' => $this->get_endpoints(),
'i18n' => array(
'formUpdated' => __( 'Form Updated', 'gravityforms' ),
'viewForm' => __( 'View Form', 'gravityforms' ),
'genericError' => __( 'An error occurred while saving the form.', 'gravityforms' ),
'networkError' => __( 'Request failed due to a network error. Please check your internet connection.', 'gravityforms' ),
'genericSuccess' => __( 'Form was updated successfully.', 'gravityforms' ),
'saveInProgress' => __( 'Saving', 'gravityforms' ),
'saveForm' => __( 'Save Form', 'gravityforms' ),
'saved' => __( 'Saved', 'gravityforms' ),
'ajaxErrorDialogCancelButtonText' => __( 'Cancel', 'gravityforms' ),
'ajaxErrorDialogCloseButtonTitle' => __( 'Close', 'gravityforms' ),
'ajaxErrorDialogConfirmButtonText' => __( 'Save', 'gravityforms' ),
'ajaxErrorDialogContent' => __( 'There was an error saving your form. To avoid losing your work, click the Save button to save your form and reload the page.' ),
'ajaxErrorDialogTitle' => __( 'Save Error.', 'gravityforms' ),
),
),
);
}
/**
* Gets the selectors for the UI elements in the form editor.
*
* @since 2.6
*
* @return array
*/
private function get_selectors() {
return array(
'successNotification' => '.gf_editor_status',
'failureNotification' => '.gf_editor_error',
'saveInProgress' => '.save-in-progress',
'stateElements' => array(
'.update-form-ajax',
),
'saveAnimationButtons' => array(
'.update-form-ajax',
),
);
}
/**
* Gets the endpoints for saving the form in the form editor.
*
* @since 2.6
*
* @return \array[][]
*/
private function get_endpoints() {
return array(
'form_editor_save_form' => array(
'action' => array(
'value' => GF_Save_Form_Endpoint_Form_Editor::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Save_Form_Endpoint_Form_Editor::ACTION_NAME ),
'default' => 'nonce',
),
),
);
}
/**
* The Dom Events in the form editor and what events they should trigger.
*
* @since 2.6
*
* @return \string[][]
*/
private function get_dom_events() {
return array(
array(
'name' => 'SaveRequested',
'action' => 'click',
'elementSelector' => '.update-form-ajax',
),
array(
'name' => 'SaveRequested',
'action' => 'keydown',
'elementSelector' => 'document',
'keys' => array(
83,
17,
16,
),
),
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Form_Editor\Save_Form\Endpoints;
use Gravity_Forms\Gravity_Forms\Save_Form\GF_Form_CRUD_Handler;
use Gravity_Forms\Gravity_Forms\Save_Form\GF_Save_Form_Service_Provider;
use Gravity_Forms\Gravity_Forms\Save_Form\Endpoints\GF_Save_Form_Endpoint_Admin;
use Gravity_Forms\Gravity_Forms\Form_Editor\GF_Form_Editor_Service_Provider;
use Gravity_Forms\Gravity_Forms\Form_Editor\Renderer\GF_Form_Editor_Renderer;
use Gravity_Forms\Gravity_Forms\Util\GF_Util_Service_Provider;
/**
* AJAX Endpoint for Saving the form in the main form editor.
*
* @since 2.6
*
* @package Gravity_Forms\Gravity_Forms\Save_Form\Endpoints
*/
class GF_Save_Form_Endpoint_Form_Editor extends GF_Save_Form_Endpoint_Admin {
// AJAX action name.
const ACTION_NAME = 'form_editor_save_form';
/**
* Handles a successful operation and returns the desired response.
*
* @since 2.6
*
* @param array $result The result of the operation.
*
* @return mixed
*/
protected function get_success_status_response( $result ) {
$gf_forms = $this->gf_forms;
$editor_renderer = $gf_forms::get_service_container()->get( GF_Form_Editor_Service_Provider::FORM_EDITOR_RENDERER );
$form_detail = $gf_forms::get_service_container()->get( GF_Util_Service_Provider::GF_FORM_DETAIL );
$result['updated_markup'] = $editor_renderer::render_form_editor( $this->form_id, $form_detail );
return parent::get_success_status_response( $result );
}
}