Set attachment-specific metadata in block config form

Hi there,

I want to create a module that wraps a simple JavaScript slider. Each ‘slide’ of the slider should use three pieces of configuration: title, image, target URL for when the user clicks the image.

When I use the block attachments form, I get a form “for free” that has the ability to add & remove attachments. The attachments can give me the image to use in the slider. However, I need the ability to override the title and target URL on a per-page basis.

What’s the best option to implement something like this? All of the examples of new blocks that I can find seem to use a fundamentally “flat” layout for their data; they just store primitive values as in o:block[__blockIndex__][o:data][foo] = "bar". But to represent this configuration, I would need to store arrays; is there any existing module that does something similar to this?

Thanks!
Dave

In your example:

o:block[__blockIndex__][o:data][foo]

o:data is essentially an array with one foo element. So, you could construct the array like this:

o:block[__blockIndex__][o:data][slide][0][title]
o:block[__blockIndex__][o:data][slide][0][image]
o:block[__blockIndex__][o:data][slide][0][target_url]
o:block[__blockIndex__][o:data][slide][1][title]
o:block[__blockIndex__][o:data][slide][1][image]
o:block[__blockIndex__][o:data][slide][1][target_url]

You’ll likely need some JavaScript to build this structure dynamically. The Mapping module has one example of how this works. Take a look at the Mapping block here, the template here, and the JS here.

1 Like

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.