forked from argoproject/Argo
-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1733 from INN/1683-output-largo-speicifc-photo-cr…
…edit-metadata-on-image-block Output largo specific photo credit metadata on image block
- Loading branch information
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* Enqueue scripts to extend default block editor. | ||
*/ | ||
function largo_extend_block_editor() { | ||
|
||
wp_enqueue_script( | ||
'blocks-image-customizations', | ||
get_template_directory_uri() . '/js/blocks-image-customization.js', | ||
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-api' ), | ||
'1.0.0', | ||
true | ||
); | ||
|
||
} | ||
add_action( 'enqueue_block_editor_assets', 'largo_extend_block_editor' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const { createHigherOrderComponent } = wp.compose; | ||
|
||
var largo_core_image_block_add_media_credit = createHigherOrderComponent( function ( BlockListBlock ) { | ||
|
||
return function ( props ) { | ||
|
||
if( props.name === 'core/image' ){ | ||
|
||
var attachment_id = props.attributes.id; | ||
var media = new wp.api.models.Media( { id: attachment_id } ); | ||
|
||
var media_response = media.fetch().then( function( media ) { | ||
|
||
// the original instance of the media caption | ||
var attachment_caption = props.attributes.caption; | ||
|
||
if( media.media_credit && ( media.media_credit._media_credit || media.media_credit._navis_media_credit_org ) ){ | ||
|
||
// if both the credit and organization are present | ||
if( media.media_credit._media_credit && media.media_credit._navis_media_credit_org ){ | ||
|
||
var media_credit = media.media_credit._media_credit+' / '+media.media_credit._navis_media_credit_org; | ||
|
||
// if only the credit is present | ||
} else if( media.media_credit._media_credit ){ | ||
|
||
var media_credit = media.media_credit._media_credit; | ||
|
||
// if only the org is present | ||
} else if( media.media_credit._navis_media_credit_org ){ | ||
|
||
var media_credit = media.media_credit._navis_media_credit_org; | ||
|
||
} | ||
|
||
// if the media credit url exists, wrap the media credit with it | ||
if( media.media_credit._media_credit_url ){ | ||
|
||
var media_credit = '<a href="'+media.media_credit._media_credit_url+'">'+media_credit+'</a>'; | ||
|
||
} | ||
|
||
// our full media credit | ||
var media_credit = '<p class="wp-media-credit">'+media_credit+'</p>'; | ||
|
||
// if our media attachment caption already includes `largo-attachment-media-credit`, | ||
// which is the class of our span, don't do anything more | ||
if( ! attachment_caption.includes( 'wp-media-credit' ) ){ | ||
|
||
var attachment_caption = media_credit + attachment_caption; | ||
|
||
props.attributes.caption = attachment_caption; | ||
|
||
} | ||
|
||
} | ||
|
||
}); | ||
|
||
} | ||
|
||
return React.createElement( BlockListBlock, props ); | ||
|
||
}; | ||
|
||
}, 'largo_core_image_block_add_media_credit'); | ||
|
||
wp.hooks.addFilter( | ||
'editor.BlockEdit', | ||
'largo-core-block-customizations/editor/block-edit', | ||
largo_core_image_block_add_media_credit | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters