Skip to content

Bindings: Try to integrate SCF custom fields in the Attributes panel #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion includes/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@ public function register_scripts() {
)
);

wp_add_inline_script(
'wp-blocks',
'const originalBlocks = window.wp.blocks;

window.wp.blocks = new Proxy(originalBlocks, {
get(target, prop, receiver) {
if (prop === "getBlockBindingsSources") {
return function(...args) {
const result = target.getBlockBindingsSources(...args);
if (result?.["acf/field"]) {
result["acf/field"]["getFieldsList"] = function() {
return acf.getFields().reduce( (acc, { data, $el }) => {
acc[data.name] = {
label: $el.find("label").text(),
value: $el.find("input").val() || "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this won't work for fields different that the text one. (For example the textarea).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it would have to cover all types of input from different field types. I covered the happy path for the text field as it's the only one supported in the Attributes panel anyway.

type: data.type === "text" ? "string" : data.type,
};
return acc;
}, {} );
};
}
return result;
};
}

return Reflect.get(target, prop, receiver);
}
});',
'after'
);

// Register styles.
foreach ( $styles as $style ) {
wp_register_style(
Expand Down Expand Up @@ -753,4 +784,4 @@ function acf_enqueue_scripts( $args = array() ) {
*/
function acf_enqueue_uploader() {
return acf_get_instance( 'ACF_Assets' )->enqueue_uploader();
}
}
Loading