Skip to content
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

<MediaUpload /> How to retrive image title, alt & description? #16613

Closed
mathishuettl opened this issue Jul 16, 2019 · 3 comments
Closed

<MediaUpload /> How to retrive image title, alt & description? #16613

mathishuettl opened this issue Jul 16, 2019 · 3 comments
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@mathishuettl
Copy link

mathishuettl commented Jul 16, 2019

Hello,

I use the component. When i log the output in the onSelect callback I can't find the title tag. Only the alt & caption are there. How can I get alt, title & description for an image?

@mathishuettl mathishuettl changed the title <MediaUpload /> How to retrive image description and label? <MediaUpload /> How to retrive image title, alt & description? Jul 16, 2019
@swissspidy swissspidy added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] Media Anything that impacts the experience of managing media labels Jul 16, 2019
@mathishuettl
Copy link
Author

I found a solution ... is that a good one?

I use the HOC withSelect to get all the image-details:

export default withSelect( ( select, ownProps ) => {
	const { getMedia } = select( 'core' );
	const { id } = ownProps;

    let img = id ? getMedia(id) : null;

	return {
		image: img,
	};
} )( GalleryImage );

And in the ComponentDidUpdate I retrive the author (description)

componentDidUpdate() {
        const { image, author, setAttributes } = this.props;

        if (image && !author && !this.state.gotAuthor ) {
            setAttributes( { author: image.description.raw, } );
            this.setState( { gotAuthor: true } );
        }
    }

@youknowriad
Copy link
Contributor

That's a great one :)

@andfinally
Copy link

For anyone else looking for this functionality, when the user selects an image, onSelect now returns an object including alt, author, caption and other useful details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants