Bruno17 / MIGX

MIGX for revo 2.2 and above
83 stars 78 forks source link

[[ImagePlus]] in renderchunktpl causes issues #354

Closed BenceSzalai closed 3 years ago

BenceSzalai commented 4 years ago

I'm trying to manually render an ImagePlus TV in the MIGX grid. I know I could just use ImagePlus.MIGX_Renderer, but I'd like to control what to render based on other TVs, so I need to use a custom chunk. However the problem is that as soon as I call [[ImagePlus... inside the renderchunktpl MIGX produces number of issues:

If I remove the [[ImagePlus... snippet call from the renderchunktpl everything works fine, so I assume my configuration is OK otherwise.

In the error log I see these related entries when I have the [[ImagePlus... included, but these are not there when I don't use the ImagePlus snippet call:

[2020-01-03 09:50:43] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"
[2020-01-03 09:50:43] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"
[2020-01-03 09:50:50] (WARN @ .../core/components/migx/processors/mgr/default/handlecolumnswitch.php : 71) PHP notice: Undefined index: classname
[2020-01-03 09:50:50] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"
[2020-01-03 09:50:50] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"
[2020-01-03 09:50:51] (WARN @ .../core/components/migx/processors/mgr/default/handlecolumnswitch.php : 71) PHP notice: Undefined index: classname
[2020-01-03 09:50:51] (WARN @ .../core/components/migx/processors/mgr/default/handlecolumnswitch.php : 106) PHP notice: Undefined offset: 2
[2020-01-03 09:50:52] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"
[2020-01-03 09:50:52] (DEBUG @ .../core/model/modx/modlexicon.class.php : 416) Language string not found: "imageplus.imageplus.fromJson"

In fact if I turn off "extrahandlers":"this.handleColumnSwitch" (which I have enabled to allow a checkbox to be changed from the grid, without opening the row in the editor) the warnings from .../core/components/migx/processors/mgr/default/handlecolumnswitch.php go away, but the issues remain...

The renderchunktpl I'm trying to use is very simple for now: [[ImagePlus? &value=`[[+image]]`]] I'd use a more complex one should I get this to working.

Also: The issue is the same even if I hide the column with the custom render chunk using the ImagePlus snippet. So it doesn't matter if the column is shown or hidden. The only way to get MIGX to work is to remove any calls to ImagePlus snippet from the renderer chunk code.

More updates: I can see a sample code here: https://forums.modx.com/thread/80338/migx---new-feature-renderchunk?page=4#dis-post-485293 In this post the snippet to be used is not [[ImagePlus... but [[renderImagePlus... however I don't see such snippet included with either MIGX or ImagePlus, so I've assumed it is just an old name for the same, but I' not sure.

Similar case was reported here: https://forums.modx.com/thread/102772/nested-migx-with-imageplus-output-breaks-my-migx-table#dis-post-553607

If I call the ImagePlus-Plugin with a renderChunk-Tpl to get a cropped image in my MIGX-table, the hole story fails. (sic)

AFAICS, this is a very similar experience whereas using [[ImagePlus in renderchunktpl resulted in issues.

BenceSzalai commented 4 years ago

Investigation goes on: I've realised that when I have [[ImagePlus... in renderchunktpl the requests to assets/components/migx/connector.php fail with 500 Internal Server Error.

From PHP side it gives me this:

Fatal error: Uncaught Error: Call to a member function get() on null in .../core/cache/includes/elements/modsnippet/11.include.cache.php:27 Stack trace: #0 .../core/model/modx/modscript.class.php(76): include() #1 .../core/model/modx/modparser.class.php(537): modScript->process(NULL) #2 .../core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag(Array, false) #3 .../core/model/modx/modparser.class.php(251): pdoParser->processTag(Array, false) #4 .../core/components/pdotools/model/pdotools/pdoparser.class.php(65): modParser->processElementTags('[[$?MIGX_id=`1`...', '[[ImagePlus? &v...', false, false, '[[', ']]', Array, 9) #5 .../core/model/modx/modchunk.class.php(123): pdoParser->processElementTags('[[$?MIGX_id=`1`...', '[[ImagePlus? &v...', false, false, '[[', ']]', Array, 10) #6 /home/webdev/publi in .../core/cache/includes/elements/modsnippet/11.include.cache.php on line 27

Where modsnippet/11.include.cache.php is the cached PHP of the ImagePlus snippet. So after all the issue is with this line: $docid = $modx->getOption('docid', $scriptProperties, $modx->resource->get('id'), true);

Well one thing is that $modx->resource is simply not defined when the connector is being processed. I'm not that familiar with the MODX system, to be able to tell if that would be even possible to be set at this point. If so, MIGX should make sure $modx->resource is set to the correct resource when connector.php is being processed.

But the other question is why ImagePlus is even trying to do this?

So the solution is:

And in fact it'd be nice to wrap the $modx->resource in a try block to make failures more graceful.

So the workaround solution is to make sure to call ImagePlus snippet with at least two parameters: [[ImagePlus? &docid=`[[*id]]` &value=`[[+image]]`]]

and replace line 27 in the ImagePlus snippet with this:

$docid = $modx->getOption('docid', $scriptProperties, '', true);
if ( '' === $docid ) {
    if ( ! isset( $modx->resource ) ) {
        $modx->log(xPDO::LOG_LEVEL_ERROR, 'Unable to determine the ID of the current resource.', '', 'Image+');
        return 'Unable to determine the ID of the current resource.';
    }
    $docid = $modx->resource->get('id');
}

I'll try to submit that to the ImagePlus repo as well (https://github.com/Jako/ImagePlus/pull/84), but meanwhile I'll leave this issue open for MIGX too with the following note:

MIGX does not set $modx->resource when processing the calls from the manager interface to assets/components/migx/connector.php.

Bruno17 commented 3 years ago

Closing this, since it seems to be solved now