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

Content Lib - Image Component - Return image reference #7284

Closed
abdavid opened this issue Aug 5, 2019 · 6 comments
Closed

Content Lib - Image Component - Return image reference #7284

abdavid opened this issue Aug 5, 2019 · 6 comments
Assignees
Milestone

Comments

@abdavid
Copy link

abdavid commented Aug 5, 2019

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() and contentLib.get() to verify that the image id is missing from the result;

Actual

"page": {
        "type": "page",
        "path": "/",
        "descriptor": "com.somesite.someapp",
        "config": {},
        "regions": {
            "main": {
                "components": [
                    {
                        "path": "/main/0",
                        "type": "image"
                    }
                ]
            }
        }
    },

Expected

"page": {
        "type": "page",
        "path": "/",
        "descriptor": "com.somesite.someapp:default",
        "config": {},
        "regions": {
            "main": {
                "components": [
                    {
                        "path": "/main/0",
                        "type": "image",
                        "image": {
                             "id": "image-id"
                        } 
                    }
                ]
            }
        }
    },

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

@alansemenov
Copy link
Member

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.

@abdavid
Copy link
Author

abdavid commented Aug 6, 2019

@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 :)

@alansemenov
Copy link
Member

alansemenov commented Aug 6, 2019

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.

@GlennRicaud GlennRicaud assigned ashklianko and unassigned GlennRicaud Aug 6, 2019
@abdavid
Copy link
Author

abdavid commented Aug 6, 2019 via email

@alansemenov
Copy link
Member

It's probably this one. Already fixed and will be released in Content Studio 2.0.2.

@alansemenov alansemenov assigned vbradnitski and unassigned ashklianko Aug 8, 2019
@GlennRicaud GlennRicaud changed the title [BUG] Add missing image component type support to ComponentMapper.java Content Lib - Image Component - Return image reference Aug 16, 2019
@GlennRicaud GlennRicaud added this to the 7.0.3 milestone Aug 16, 2019
@GlennRicaud
Copy link
Contributor

GlennRicaud commented Aug 16, 2019

Thank you for reporting this issue.
This will be released with content library 7.0.3 and 7.1.0

@jsi jsi modified the milestones: 7.0.3, 7.1.0 Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants