-
Notifications
You must be signed in to change notification settings - Fork 182
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
Get_block_wrapper_attributes missing align class #756
Comments
There is this filter with which we can determine the output of the class names ourselves. var {
createHigherOrderComponent,
} = wp.compose;
var {
createElement,
} = wp.element;
var el = createElement;
/*
* BlockListBlock filter modifications
*/
var blockListBlockFilter = createHigherOrderComponent( function ( BlockListBlock ) {
return function( props ) {
const blockName = props.block.name ? props.block.name : null;
const blockAlign = props.attributes.align ? props.attributes.align : null;
const originalListBlock = el( BlockListBlock, props );
// We modify this for our acf blocks only
if( ! blockName || ! blockName.includes('acf/') ) {
// Return unmodified block wrapper
return originalListBlock;
}
if( ! blockAlign ) {
// Return unmodified block wrapper
return originalListBlock;
}
// Set the block align class name to the ACF block wrapper
var newProps = {
...props,
className: 'align' + props.attributes.align,
};
return el( BlockListBlock, newProps );
};
}, 'blockListBlockFilter' );
wp.hooks.addFilter( 'editor.BlockListBlock', 'my-plugin/blockListBlockFilter', blockListBlockFilter ); |
I'm running into the same issue but with the textAlign support. Have you found a solution yet? |
The only way ACF could go is to provide a filter where the user can specify the class names themselves. There is no guideline as to what the class names should be. The user can influence this. I mentioned above one way how we could do that. In the PHP template, the user can already independently influence the output of the classes. If you also output these classes to the surrounding wrapper, the classes are then also available twice. |
Same problem! Because native block attributes are missing, the A solution would be to include "native" attributes to block. If possibile |
While it surely isn't intuitive, textAlign isn't actually supposed to be here because it isn't part of the core block supports: https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-supports.md If you look at some of the core blocks that support textAlign, you can see how this is handled. For example, in post-title.php: `$classes = array();
|
This may be similar to #739, but when creating a simple ACF block test using the
get_block_wrapper_attributes
function in my render file, it outputs the top level class for my block name (.wp-block-cab-test
), but doesn't output the wide alignment class that I've set on the block by default. It shows wide on the backend, but when I change it to alignnone, on the frontend it now outputs an extra class of justalign
.Doing the same test in a custom (non-ACF) WP block outputs the align class correctly, so I wanted to see if I was missing something here or merely
_doing_it_wrong
.Here's a simplified test block for reference.
The text was updated successfully, but these errors were encountered: