Closed abdavid closed 5 years ago
Hi, and thanks for reporting this. We'll check why image
property is not available on the content level. As a workaround, you can retrieve it on the node level, like this (assuming you know contentId and component path inside content):
var nodeLib = require('/lib/xp/node');
var repo = nodeLib.connect({
repoId: 'com.enonic.cms.default',
branch: 'draft'
});
var node = repo.get(contentId);
log.info(JSON.stringify(node, null, 4));
if (node && node.components) {
var imageObject = node.components.filter(function (component) {
return component.type == 'image' && component.path == '/main/0';
})[0];
log.info(JSON.stringify(imageObject.image, null, 4));
}
This will give you an object with id
and caption
.
@alansemenov Thanks for the swift reply! this is really why I keep lobbying (among other things) for XP!
I found another work around - I just created a part with a simple ImageSelector and instead of adding the base Image component I just add my custom Image part though I would rather prefer being able to use the "native" Image component as it is confusing for editors :)
I'd actually recommend inserting an image via Text component - this would give you more opportunities for image styling via custom styles (where you can combine server-side processing with CSS) plus being able to change alignment, add caption etc. Image references will be extracted on save and available in the content object where you could easily retrieve them from.
But whatever works for you, we'll still look at this bug.
I am actually having issues with the text component aswell. Running contentstudio 2.0.0. Looks like issues with ckeditor and locales.
- aug. 2019 kl. 10:51 skrev Alan Semenov notifications@github.com:
I'd actually recommend inserting an image via Text component - this would give you more opportunities for image styling via custom styles (where you can combine server-side processing with CSS) plus being able to change alignment, add caption etc. Image references will be extracted on save and stored in the content object where you could easily retrieve them from.
But whatever works for you, we'll still look at this bug.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
It's probably this one. Already fixed and will be released in Content Studio 2.0.2.
Thank you for reporting this issue. This will be released with content library 7.0.3 and 7.1.0
Missing image component type in ComponentMapper class.
I came over this issue when adding an image component to a simple page controller and wanting to use the image id to generate an image url.
First I verified with Data Toolbox that the image was actually there containing an id with reference to the image.
Secondly I used
contentLib.query()
andcontentLib.get()
to verify that the image id is missing from the result;Actual
Expected
I then started poking around in the content-lib code and found the ComponentMapper class, and from what I can see this class i responsible for mapping a Component -- But I cannot see any references to how Image components are handled which in turn also might explain why I am missing it in the result set.
-- David