applyContext.js
24 lines
| 1 | /** |
| 2 | * Applies the context to the attributes. |
| 3 | * |
| 4 | * @param {Object} context The block context. |
| 5 | * @param {Object} attributes The block attributes. |
| 6 | * @return {Object} The attributes. |
| 7 | */ |
| 8 | export default function applyContext( context, attributes ) { |
| 9 | if ( attributes.dynamicSource === 'current-post' ) { |
| 10 | if ( attributes.isCaption ) { |
| 11 | // Set the static post ID for the dynamic headline. |
| 12 | context.postId = !! context[ 'generateblocks/dynamicImage' ] |
| 13 | ? context[ 'generateblocks/dynamicImage' ] |
| 14 | : context[ 'generateblocks/mediaId' ]; |
| 15 | |
| 16 | context.postType = 'attachment'; |
| 17 | } |
| 18 | |
| 19 | return Object.assign( {}, attributes, context ); |
| 20 | } |
| 21 | |
| 22 | return attributes; |
| 23 | } |
| 24 |