Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Fix/676 gf file upload issue #678

Draft
wants to merge 10 commits into
base: canary
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"require": {
"dre1080/wp-graphql-upload": "^0.1",
"harness-software/wp-graphql-gravity-forms": "^0.4",
"pristas-peter/wp-graphql-gutenberg": "^0.3",
"pristas-peter/wp-graphql-gutenberg": "^0.6",
"wds/wds-headless-acf": "^1.0",
"wds/wds-headless-algolia": "^1.0",
"wds/wds-headless-blocks": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/wds-headless-blocks/inc/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ function enqueue_block_editor_assets() {
true
);
}
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_editor_assets' );
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_editor_assets', 1 );
318 changes: 166 additions & 152 deletions backend/plugins/wds-headless-blocks/js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* @since 1.0.0
*/

const { validateThemeColors, validateThemeGradients } = wp.blockEditor;
const { useEffect } = wp.element;
const { addFilter, applyFilters } = wp.hooks;
const {validateThemeColors, validateThemeGradients} = wp.blockEditor
const {useEffect, createElement} = wp.element
const {addFilter, applyFilters} = wp.hooks
const {createHigherOrderComponent} = wp.compose

/**
* Customize core block settings.
Expand All @@ -17,162 +18,175 @@ const { addFilter, applyFilters } = wp.hooks;
* @since 1.0.0
*/
wp.domReady(() => {
wp.blocks.unregisterBlockStyle("core/image", "default");
wp.blocks.unregisterBlockStyle("core/separator", "dots");
wp.blocks.unregisterBlockStyle("core/separator", "wide");
wp.blocks.registerBlockStyle("core/separator", {
name: "full-width",
label: "Full Width",
});
});

addFilter(
"blocks.registerBlockType",
"wds/filterBlockColorAttrs",
wdsAddColorPaletteHexValues
);
wp.blocks.unregisterBlockStyle('core/image', 'default')
wp.blocks.unregisterBlockStyle('core/separator', 'dots')
wp.blocks.unregisterBlockStyle('core/separator', 'wide')
wp.blocks.registerBlockStyle('core/separator', {
name: 'full-width',
label: 'Full Width'
})
})

/**
* Filter block registration to add custom color attributes to specified blocks.
* Filter block registration to add custom color attributes.
*
* @author WebDevStudios
* @since 1.0.0
* @param {object} settings Block settings config.
* @return {object} Block settings config.
*/
function wdsAddColorPaletteHexValues(settings) {
// Add background color hex attribute.
if (settings.attributes.hasOwnProperty("backgroundColor")) {
settings.attributes.backgroundColorHex = {
type: "string",
default: "",
};
}

// Add gradient background hex attribute.
if (settings.attributes.hasOwnProperty("gradient")) {
settings.attributes.gradientHex = {
type: "string",
default: "",
};
}

// Add main color hex attribute.
if (settings.attributes.hasOwnProperty("mainColor")) {
settings.attributes.mainColorHex = {
type: "string",
default: "",
};
}

// Add overlay color hex attribute.
if (settings.attributes.hasOwnProperty("overlayColor")) {
settings.attributes.overlayColorHex = {
type: "string",
default: "",
};
}

// Add text color hex attribute.
if (settings.attributes.hasOwnProperty("textColor")) {
settings.attributes.textColorHex = {
type: "string",
default: "",
};
}

return {
...settings,
edit(props) {
const {
attributes: {
backgroundColor,
gradient,
mainColor,
overlayColor,
textColor,
},
} = props;

useEffect(() => {
// Note: This may not work as expected if a custom theme palette has been set.
// In that case, this filter may need to be customized.
const defaultColors = validateThemeColors();

const defaultGradients = validateThemeGradients();

// Check for presence of background color attr.
if (backgroundColor) {
// Get color object by slug.
const backgroundColorObj = defaultColors.filter(
(color) => color.slug === backgroundColor
);

// Retrieve color hex value.
props.attributes.backgroundColorHex =
backgroundColorObj?.[0]?.color || null;
} else {
delete props.attributes.backgroundColorHex;
}

// Check for presence of gradient color attr.
if (gradient) {
// Get color object by slug.
const gradientObj = defaultGradients.filter(
(color) => color.slug === gradient
);

// Retrieve color hex value.
props.attributes.gradientHex =
gradientObj?.[0]?.gradient || null;
} else {
delete props.attributes.gradientHex;
}

// Check for presence of main color attr.
if (mainColor) {
// Get color object by slug.
const mainColorObj = defaultColors.filter(
(color) => color.slug === mainColor
);

// Retrieve color hex value.
props.attributes.mainColorHex =
mainColorObj?.[0]?.color || null;
} else {
delete props.attributes.mainColorHex;
}

// Check for presence of overlay color attr.
if (overlayColor) {
// Get color object by slug.
const overlayColorObj = defaultColors.filter(
(color) => color.slug === overlayColor
);

// Retrieve color hex value.
props.attributes.overlayColorHex =
overlayColorObj?.[0]?.color || null;
} else {
delete props.attributes.overlayColorHex;
}

// Check for presence of text color attr.
if (textColor) {
// Get color object by slug.
const textColorObj = defaultColors.filter(
(color) => color.slug === textColor
);

// Retrieve color hex value.
props.attributes.textColorHex =
textColorObj?.[0]?.color || null;
} else {
delete props.attributes.textColorHex;
}
}, [backgroundColor, mainColor, textColor]);

return settings.edit(props);
},
};
const attributes = {}

// Add background color hex attribute.
if (settings.attributes.hasOwnProperty('backgroundColor')) {
attributes.backgroundColorHex = {
type: 'string',
default: ''
}
}

// Add gradient background hex attribute.
if (settings.attributes.hasOwnProperty('gradient')) {
attributes.gradientHex = {
type: 'string',
default: ''
}
}

// Add main color hex attribute.
if (settings.attributes.hasOwnProperty('mainColor')) {
attributes.mainColorHex = {
type: 'string',
default: ''
}
}

// Add overlay color hex attribute.
if (settings.attributes.hasOwnProperty('overlayColor')) {
attributes.overlayColorHex = {
type: 'string',
default: ''
}
}

// Add text color hex attribute.
if (settings.attributes.hasOwnProperty('textColor')) {
attributes.textColorHex = {
type: 'string',
default: ''
}
}

return lodash.assign({}, settings, {
attributes: lodash.assign({}, settings.attributes, attributes)
})
}

addFilter(
'blocks.registerBlockType',
'wds/filterBlockColorAttrs',
wdsAddColorPaletteHexValues
)

/**
* Filter block edit function to set custom color attributes.
*
* @author WebDevStudios
* @since 1.0.1
*/
const withColorPaletteHexValues = createHigherOrderComponent((BlockEdit) => {
return (props) => {
const {
attributes: {
backgroundColor,
gradient,
mainColor,
overlayColor,
textColor
}
} = props

useEffect(() => {
// Note: This may not work as expected if a custom theme palette has been set.
// In that case, this filter may need to be customized.
const defaultColors = validateThemeColors()

const defaultGradients = validateThemeGradients()

// Check for presence of background color attr.
if (backgroundColor) {
// Get color object by slug.
const backgroundColorObj = defaultColors.filter(
(color) => color.slug === backgroundColor
)

// Retrieve color hex value.
props.attributes.backgroundColorHex =
backgroundColorObj?.[0]?.color || null
} else {
delete props.attributes.backgroundColorHex
}

// Check for presence of gradient color attr.
if (gradient) {
// Get color object by slug.
const gradientObj = defaultGradients.filter(
(color) => color.slug === gradient
)

// Retrieve color hex value.
props.attributes.gradientHex = gradientObj?.[0]?.gradient || null
} else {
delete props.attributes.gradientHex
}

// Check for presence of main color attr.
if (mainColor) {
// Get color object by slug.
const mainColorObj = defaultColors.filter(
(color) => color.slug === mainColor
)

// Retrieve color hex value.
props.attributes.mainColorHex = mainColorObj?.[0]?.color || null
} else {
delete props.attributes.mainColorHex
}

// Check for presence of overlay color attr.
if (overlayColor) {
// Get color object by slug.
const overlayColorObj = defaultColors.filter(
(color) => color.slug === overlayColor
)

// Retrieve color hex value.
props.attributes.overlayColorHex = overlayColorObj?.[0]?.color || null
} else {
delete props.attributes.overlayColorHex
}

// Check for presence of text color attr.
if (textColor) {
// Get color object by slug.
const textColorObj = defaultColors.filter(
(color) => color.slug === textColor
)

// Retrieve color hex value.
props.attributes.textColorHex = textColorObj?.[0]?.color || null
} else {
delete props.attributes.textColorHex
}
}, [backgroundColor, mainColor, textColor])

return createElement(BlockEdit, props)
}
}, 'withColorPaletteHexValues')

addFilter(
'editor.BlockEdit',
'wds/filterBlockEditColorAttrs',
withColorPaletteHexValues
)
4 changes: 2 additions & 2 deletions backend/plugins/wds-headless-blocks/wds-headless-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: WDS Headless extension handling Gutenberg block functionality.
* Author: WebDevStudios <[email protected]>
* Author URI: https://webdevstudios.com
* Version: 1.0.0
* Version: 1.0.1
* Requires at least: 5.6
* Requires PHP: 7.4
* License: GPL-2
Expand All @@ -23,7 +23,7 @@
// Define constants.
define( 'WDS_HEADLESS_BLOCKS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WDS_HEADLESS_BLOCKS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'WDS_HEADLESS_BLOCKS_VERSION', '1.0.0' );
define( 'WDS_HEADLESS_BLOCKS_VERSION', '1.0.1' );

// Register de/activation hooks.
register_activation_hook( __FILE__, __NAMESPACE__ . '\activation_callback' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ export default function processGfFieldValues(entryData, fieldData) {
break

case 'EmailField':
// TODO: As of WP GraphQL Gravity Forms v.0.4.1, this is accurate, but it appears it may be changing to a nested version in the next release: fieldValue.emailValues = { value, confirmationValue }.
fieldValue.value = entryData[fieldName]
fieldValue.emailValues = {
value: entryData[fieldName],
confirmationValue: entryData[fieldName]
}
break

case 'FileUploadField':
Expand Down
Loading