verbb / vizy

A flexible visual editor for Craft CMS
Other
43 stars 8 forks source link

GQL response: provide access to the AssetInterface object under VizyNode_Image #129

Closed tremby closed 2 years ago

tremby commented 2 years ago

What are you trying to do?

Render good HTML for images coming back from the wysiwyg field.

What's your proposed solution?

Right now after selecting all possible fields in the query for VizyNode_Image I only get data such as this:

            {
              "type": "image",
              "tagName": "img",
              "text": "",
              "rawNode": "{\"type\":\"image\",\"attrs\":{\"id\":98,\"src\":\"http://my-host/my-image.jpg\",\"alt\":\"Placeholder image 1\",\"title\":\"\",\"url\":null,\"target\":\"\",\"transform\":\"\"}}",
              "marks": "[]",
              "html": "<img src=\"http://my-host/my-image.jpg\" alt=\"Placeholder image 1\" title=\"\">",
              "attrs": "{\"id\":98,\"src\":\"http://my-host/my-image.jpg\",\"alt\":\"Placeholder image 1\",\"title\":\"\",\"url\":null,\"target\":\"\",\"transform\":\"\"}",
              "content": "[]"
            },

Whereas I want things like

So what I'd really like is a link through to the associated AssetInterface object, where I could query for any of those things I need.

I think the id which I see there as 98 within attrs is in fact the asset ID, so I could in theory make another query after getting this response. But it would be much cleaner and faster to get everything I need in one query.

tremby commented 2 years ago

Or am I better off not allowing plain images, and instead using a Vizy Node with an asset field?

engram-design commented 2 years ago

Added support to query asset on a VizyNode_Image for the next release. This will allow you to query everything you'd normally do on an asset element. To get this early, change your verbb/vizy requirement in composer.json to:

"require": {
  "verbb/vizy": "dev-craft-3 as 1.0.13",
  "...": "..."
}

Then run composer update.

tremby commented 2 years ago

Thank you. I can only use the Craft 4 version at present; I hope this'll make it into that before too long.

engram-design commented 2 years ago

Added in 2.0.0-beta.4