Issue #2504Opened January 12, 2020by andrewryan19060 reactions

How to extend the image asset type to add custom attributes?

Question

Hello,

I'm trying to make a simple modification to the default image asset and am running into a wall, and am sure I'm missing something simple.

I need the image element to have an additional attribute that I pass into it, called mySpecialId. I can't figure out how to get the asset to render this into the DOM.

I think I'm supposed to extend the image type like this, and I think I should be using the updateTarget method like this:

am.addType('image', {
    view: {
      updateTarget( target) {
 
..some code here, but what?
      }


    },
     
  });

But it's not working. When I click on the image, nothing happens. I think that's because I'm replacing the base updateTarget logic in the image, whereas I want to extend it.

When I try to create my own, second asset type - image2 - nothing renders in the asset explorer. I think that's because the default asset render command only renders assets of type image, but I can't figure out how/where to make it render other kinds of objects when someone drags an Image onto the canvas.

Help greatly appreciated.

Thanks Andrew

Answers (1)

artfJanuary 12, 20200 reactions
editor.AssetManager.addType('image', {
	view: {
		attributes: { 'custom-attr': 'custom-value' }
	}
});

Put it in a plugin if you need to update also the already defined assets

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.