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,147 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Editor_Button;
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Service_Provider;
use Gravity_Forms\Gravity_Forms\Editor_Button\Config\GF_Editor_Config;
use Gravity_Forms\Gravity_Forms\Editor_Button\Dom\GF_Editor_Button;
use Gravity_Forms\Gravity_Forms\Editor_Button\Endpoints\GF_Editor_Save_Editor_Settings;
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
/**
* Class GF_Editor_Service_Provider
*
* Service provider for the Embed Form Service.
*
* @package Gravity_Forms\Gravity_Forms\Editor_Button;
*/
class GF_Editor_Service_Provider extends GF_Service_Provider {
// Configs
const EDITOR_CONFIG = 'editor_config';
const ENDPOINTS_CONFIG = 'editor_endpoints_config';
// DOM
const DOM_EDITOR_BUTTON = 'dom_editor_button';
/**
* Array mapping config class names to their container ID.
*
* @since 2.8
*
* @var string[]
*/
protected $configs = array(
self::EDITOR_CONFIG => GF_Editor_Config::class,
);
/**
* Register services to the container.
*
* @since 2.6
*
* @param GF_Service_Container $container
*/
public function register( GF_Service_Container $container ) {
// Configs
require_once( plugin_dir_path( __FILE__ ) . '/config/class-gf-editor-config.php' );
// Dom
require_once( plugin_dir_path( __FILE__ ) . '/dom/class-gf-editor-button.php' );
// Endpoints
require_once( plugin_dir_path( __FILE__ ) . '/endpoints/class-gf-editor-save-editor-settings.php' );
$container->add( self::ENDPOINTS_CONFIG, function () {
return new GF_Editor_Save_Editor_Settings();
} );
$this->add_configs( $container );
$this->dom( $container );
}
/**
* Initialize any actions or hooks.
*
* @since 2.6
*
* @param GF_Service_Container $container
*
* @return void
*/
public function init( GF_Service_Container $container ) {
add_action( 'gform_after_toolbar_buttons', function () use ( $container ) {
$container->get( self::DOM_EDITOR_BUTTON )->output_button();
} );
add_action( 'wp_ajax_' . GF_Editor_Save_Editor_Settings::ACTION_NAME, function () use ( $container ) {
$container->get( self::ENDPOINTS_CONFIG )->handle();
} );
}
/**
* 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 ) {
foreach ( $this->configs as $name => $class ) {
$container->add( $name, function () use ( $container, $class ) {
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 DOM-related services.
*
* @since 2.6
*
* @param GF_Service_Container $container
*
* @return void
*/
private function dom( GF_Service_Container $container ) {
$container->add( self::DOM_EDITOR_BUTTON, function() {
return new GF_Editor_Button();
});
}
/**
* Determine if the compact view is enabled for the given form and user.
*
* @since 2.8
*
* @param int $user_id The user ID.
* @param int $form_id The form ID.
*
* @return bool
*/
public static function is_compact_view_enabled( $user_id, $form_id ) {
$compact_view = get_user_meta( $user_id, 'gform_compact_view_' . $form_id, true );
return $compact_view === 'enable';
}
/**
* Determine if the field ID view in compact view is enabled for the given form and user.
*
* @since 2.8
*
* @param int $user_id The user ID.
* @param int $form_id The form ID.
*
* @return bool
*/
public static function is_field_id_enabled( $user_id, $form_id ) {
$field_id = get_user_meta( $user_id, 'gform_compact_view_show_id_' . $form_id, true );
return $field_id === 'enable';
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Editor_Button\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
use Gravity_Forms\Gravity_Forms\Editor_Button\GF_Editor_Service_Provider;
use Gravity_Forms\Gravity_Forms\Editor_Button\Endpoints\GF_Editor_Save_Editor_Settings;
/**
* Config items for the Editor Settings Button
*
* @since 2.8
*/
class GF_Editor_Config extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
/**
* Determine if the config should enqueue its data.
*
* @since 2.8
*
* @return bool
*/
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'editor_button' => array(
'i18n' => array(
'title' => esc_html__( 'Editor Preferences', 'gravityforms' ),
'closeButtonAriaLabel' => esc_html__( 'Close button', 'gravityforms' ),
'description' => esc_html__( 'Change options related to the form editor.', 'gravityforms' ),
'compactToggleLabel' => esc_html__( 'Compact View', 'gravityforms' ),
'compactToggleText' => esc_html__( 'Simplify the preview of form fields for a more streamlined editing experience.', 'gravityforms' ),
'idToggleLabel' => esc_html__( 'Show Field IDs', 'gravityforms' ),
'idToggleText' => esc_html__( 'Show the ID of each field in Compact View.', 'gravityforms' ),
),
'endpoints' => $this->get_endpoints(),
'compactViewEnabled' => GF_Editor_Service_Provider::is_compact_view_enabled( get_current_user_id(), rgget( 'id' ) ),
'fieldIdEnabled' => GF_Editor_Service_Provider::is_field_id_enabled( get_current_user_id(), rgget( 'id' ) ),
'form' => rgget( 'id' ),
),
'dropdown_menu' => array(
'i18n' => array(
'duplicateButtonLabel' => esc_html__( 'Duplicate', 'gravityforms' ),
'deleteButtonLabel' => esc_html__( 'Delete', 'gravityforms' ),
'dropdownButtonLabel' => esc_html__( 'Dropdown menu button', 'gravityforms' ),
),
),
),
);
}
/**
* Gets the endpoints for saving the compact view settings.
*
* @since 2.8
*
* @return \array[][]
*/
private function get_endpoints() {
return array(
'save_editor_settings' => array(
'action' => array(
'value' => GF_Editor_Save_Editor_Settings::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Editor_Save_Editor_Settings::ACTION_NAME ),
'default' => 'nonce',
),
),
);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Editor_Button\Dom;
/**
* Handle outputting the Embed Button in the UI.
*
* @since 2.6
*
* @package Gravity_Forms\Gravity_Forms\Embed_Form\Dom
*/
class GF_Editor_Button {
/**
* Output the HTML for the Embed Button.
*/
public function output_button() {
?>
<button
data-js="editor-flyout-trigger"
class="gform-button gform-button--icon-white gform-button--icon-editor"
aria-label="<?php esc_attr_e( 'Open editor preferences', 'gravityforms' ); ?>"
title="<?php esc_attr_e( 'Open editor preferences', 'gravityforms' ); ?>"
>
<i class="gform-icon gform-icon--cog gform-button__icon" aria-hidden="true"></i>
</button>
<?php
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Editor_Button\Endpoints;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* AJAX Endpoint for saving the compact view settings.
*
* @since 2.8
*
* @package Gravity_Forms\Gravity_Forms\Editor_Button\Endpoints
*/
class GF_Editor_Save_Editor_Settings {
// Strings
const ACTION_NAME = 'gf_save_editor_settings';
/**
* Handle the AJAX request.
*
* @since 2.8
*
* @return void
*/
public function handle() {
check_ajax_referer( self::ACTION_NAME );
$form = intval( rgpost( 'form' ) );
$user = get_current_user_id();
$name = rgpost( 'name' );
$value = rgpost( 'value' );
$value = ( $value == 'enable' ) ? 'enable' : 'disable';
update_user_meta( $user, 'gform_' . $name . '_' . $form, $value );
}
}