• Resolved Mark Howells-Mead

    (@markhowellsmead)


    I have the following two components in custom React block code.

    const srcSetAttribute = srcset => {
        return Object.entries(srcset)
            .map(([key, entry]) => <code>${entry} ${key}w</code>)
            .join(", ");
    };
    
    const FigureWithImage = ({ classNameBase, image, lazy = true, key, sizes }) => {
        if (!image.id) {
            return "";
        }
    
        const { org, srcset, attributes } = image;
        const { width, height, alt } = attributes;
    
        const srcSetString = srcSetAttribute(srcset);
    
        return (
            <figure className={<code>${classNameBase}__figure</code>}>
                <img
                    key={key}
                    src={org[0]}
                    srcSet={srcSetString}
                    sizes={sizes}
                    alt={alt}
                    className={<code>${classNameBase}__image</code>}
                    width={width}
                    height={height}
                    loading={!!lazy ? "lazy" : "eager"}
                />
            </figure>
        );
    };

    These are then used in the save function to render the content to be saved to the database.

    {!!image.id && (
        <FigureWithImage
            key={image.id}
            classNameBase={classNameBase}
            image={image}
            lazy={true}
            sizes={'(min-width:1140px) 1140px, 100vw'}
        />
    )}

    If I save the post using an administrator role, then the HTML is saved correctly and contains all of the attributes. If I save the post using a user with an editor role, then the HTML is saved but only has the attributes src, alt, class, width, height and loading.

    Is this a known issue?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Gutenberg custom block saves different HTML according to user role’ is closed to new replies.