0
votes

In a custom TYPO3 8.7.12 extbase extension I am unable to f:debug items in templates.

We are in the listAction controller and simply do:

    $institutions = $this->institutionRepository->findAll();
    $this->view->assignMultiple([
        'institutions' => $institutions,
        // ... pagination limit ...
        ]
    );

And in the template:

 <f:debug>
    {institutions}                            
 </f:debug>

This returns

  • sometimes the string 'Array' in the fluid debugger (can't reproduce now)
  • When the code is on 3 lines: #1273753083: Cannot cast object of type "TYPO3\CMS\Extbase\Persistence\Generic\QueryResult" to string.
  • Or also #1273753083: Cannot cast object of type "TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage" to string.
  • When the code is on 1 line: #1234386924: Cannot create empty instance of the class "TYPO3\CMS\Extbase\Persistence\ObjectStorage" because it does not implement the TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface.

If I loop through {institutions} with f:for and then f:debug:

<f:for each="{institutions}" as="institution" iteration="i">
    <f:debug>
      {institution}
    </f:debug>
</f:for>

I get the first property of the object, e.g. the name.

EDIT: this is due to a __toString() magic method in the model. If I remove it, instead I get the namespace and uid STUBR\Extension\Domain\Model\Institution:55 – this looks again as if the object isn't rendered.

Wait... php.net says The __toString() method allows a class to decide how it will react when it is treated like a string. So could something be treating (typecasting?) the object as a string?

Working with the properties is normal, the issue just occurs when trying to print the whole object.

Where should I look? Lazy loading? There are some lazy loading properties, but not that many. Or maybe something is missing from the class? Or is there a workaround.

PS:

2
Hmmm... I had similar "surprises"... - Did you try debug() in your controller? (so not in Fluid...) - Did you try a simple $this->view->assign('institutions', $institutions) and debug $institutions? - Did you try to remove @lazy for the moment? Could you also post the Fluid code, please?Robert Wildling
Thanks for your feedback. simple $this->view->assign('institutions', $institutions) and remove @lazy: I did, no difference. Did you try debug() in your controller? There's no such php command, what do you mean? print_r uses too much memoryUrs
Thanks Robert! \TYPO3\CMS\Core\Utility\DebugUtility::debug works perfectly and produces the same output as expected from f:debugUrs
If you post that as answer I can accept itUrs

2 Answers

4
votes

To answer the question;

<f:debug>{institutions}</f:debug>

will be parsed as an object, but any whitespace inside will make it parse as a string so.

1
votes

The following methods do the same job as <f:debug> and work similarly in my case:

     \TYPO3\CMS\Core\Utility\DebugUtility::debug(
        $var = $variable,
        $header = 'Institutions',
        $group = ''
     );

     \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
        $variable,
        $title = 'Institutions', 
        $maxDepth = 8,
        $plainText = FALSE,
        $ansiColors = TRUE,
        $return = FALSE,
        $blacklistedClassNames = NULL,
        $blacklistedPropertyNames = NULL
     );

execute in list or show action in controller.

It's less convenient than with f:debug (because you have to do the work in two different places, e.g. when you're in a loop in the template, you have to go to the controller and build that loop again), but it's a helpful workaround.

EDIT: I found it's sufficient to do

<f:debug>{var}</f:debug>

on one line