Support » Plugin: AMP » Extending the Story Block doesn’t work as expected

  • Hi,

    I am trying to extend the Story Block in order to provide support for a Transcoding plugin, I want to save a custom value in an attribute created by the said plugin.

    I am able to extend and add a new setting to the Inspector Control, however the attributes aren’t being added to AMP Story Block.

    /**
     * Add background video quality attribute to block.
     *
     * @param {object} settings Current block settings.
     * @param {string} name Name of block.
     *
     * @returns {object} Modified block settings.
     */
    const addBackgroundVideoQualityControlAttribute = ( settings, name ) => {
    	if ( ! enableTranscoderSettingsOnBlocks.includes( name ) ) {
    		return settings;
    	}
    
    	//check if object exists for old Gutenberg version compatibility
    	if ( typeof settings.attributes !== 'undefined' ) {
    		settings.attributes = Object.assign( settings.attributes, {
    			rtBackgroundVideoQuality: {
    				type: 'string',
    				default: defaultVideoQuality,
    			},
    		} );
    	}
    
    	return settings;
    };
    
    addFilter( 'blocks.registerBlockType', 'transcoder/ampStoryBackgroundVideoQuality', addBackgroundVideoQualityControlAttribute );

    The above code checks block name from a constant of block on which the attribute has to be added.

    Here is the current value of the constant.

    
    // Enable Transcoder settings on the following blocks
    const enableTranscoderSettingsOnBlocks = [
    	'amp/amp-story-page',
    	'core/video',
    ];
    

    This is working as expected for the core block, however causing issue in case of the Story Block.

    I believe this is a similar issue https://github.com/WordPress/gutenberg/issues/18709

    Here is the full gist, which has current code used to achieve this https://gist.github.com/thrijith/8cff51c88151a08849faafccb7192d70

    Changing hook priority for enqueue_block_editor_assets also doesn’t work.

    Is this an expected behaviour?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pascal Birchler

    (@swissspidy)

    Hi @thrijith

    This kind of technical question is probably best suited for our GitHub repository where we’ve previously engaged on this matter. I recommend opening a new issue there.

    It’s important that your JavaScript file is enqueued before ours, make sure to check the source code in dev tools to verify this. That’s because your filter needs to be added before we’re registering the amp/amp-story-page block. So for double safety you might use a custom priority of 9 or lower for your addFilter call as well.

    It might be easier for us to assist you if you could share the link to your GitHub repository with this code of yours. Then we can just clone it and debug the code right away.

    Thanks @swissspidy

    I’ll open up an issue on the GitHub repository, I initially thought of opening one there but based on template description in the request template, I went with the forum.

    Let’s continue the discussion over there https://github.com/ampproject/amp-wp/issues/3960

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.