-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Filterable behavior for Image Block raw transformations #8473
Comments
Noting I deleted a comment which was saying the same thing over and over many times per minute in various locations. Spamming and unacceptable behavior towards anyone, or this community, will not be allowed. If you want to give feedback, please do it without spamming or personal attacks. My apologies for those who were effected during this. Please know we have a zero tolerance policy over this type of behavior. |
I made some progress on an implementation: if ( 'core/image' !== name ) {
return settings;
}
const newTransforms = [];
settings.transforms.from.forEach(( transformObj ) => {
if ( 'raw' === transformObj.type ) {
const origTransform = transformObj.transform;
const transformWrap = ( node ) => {
// Parse the Pinterest attributes and add to our central store.
const img = node.querySelector( 'img' );
const className = node.className + ' ' + img.className;
const idMatches = /(?:^|\s)wp-image-(\d+)(?:$|\s)/.exec( className );
const id = idMatches ? Number( idMatches[ 1 ] ) : undefined;
if ( id ) {
const valueKey = 'image_' + id;
// img.dataset['pin-description'] is undefined because it's already been sanitized
setStoreValue( 'descriptions', valueKey, img.dataset['pin-description'] );
}
return origTransform( node );
};
transformObj = Object.assign( transformObj, {
transform: transformWrap,
});
} else if ( 'shortcode' === transformObj.type ) {
// todo handle this too
}
newTransforms.push( transformObj );
});
settings.transforms.from = newTransforms; However, the |
@danielbachhuber, is this helpful? |
Yes, I think this would solve the problem I ran into with #8473 (comment). However, I want to see how #11440 transforms into actionable tasks before I spend too much time on this. |
Along with #10204 (comment), I've gone with this:
|
One of the plugins I work on, Tasty Pins, offers the ability to add "Pinterest Text" to an image (related #8472). When the image ends up in the Classic Editor, its markup looks like this:
Notice the inclusion of
data-pin-description="This cashew coffee is delicious, creamy, and easy. Perfect for a chilly morning! | pinchof yum.com"
.When this image is transformed to an Image Block, the
data-pin-description
attribute is lost, even though I've registered it as a custom attribute to the block (related #8470, #6878).What's the best way to filter the Image Block transform behavior? It doesn't appear plugins have much control over the behavior:
gutenberg/core-blocks/image/index.js
Lines 112 to 125 in 804abec
The text was updated successfully, but these errors were encountered: