#105600PHP Warning: Undefined array key "currentValueKey" in /var/www/html/vendor/typo3/cms-fluid/Classes/ViewHelpers/CObjectViewHelper.php line 117
Description
While invoking the CObjectViewHelper from an other Viewhelper Class, I’ve ran into undefined array key warnings:
PHP Warning: Undefined array key “currentValueKey” in /var/www/html/vendor/typo3/cms-fluid/Classes/ViewHelpers/CObjectViewHelper.php line 117
PHP Warning: Undefined array key “table” in /var/www/html/vendor/typo3/cms-fluid/Classes/ViewHelpers/CObjectViewHelper.php line 118
As those arguments registered as optional, there should be now array key warning.
My Code:
$cObjectViewHelper->setArguments([
'typoscriptObjectPath' => $blockType,
'data' => $data->getRawRecord()->toArray(),
'context' => $context,
]);
$cObjectViewHelper->setRenderingContext($subView->getRenderingContext());
$content = $cObjectViewHelper->render();
Full version: Source: https://github.com/TYPO3incubator/surfcamp-team-success/blob/main/local_packages/success/Classes/ViewHelpers/RenderBlockViewHelper.php#L87-L91
Reviews 2
Related issues 1
History 89
-
Garvin Hicking changed category <span data-processor="relativetime" data-value="2024-11-14T13:43:46+00:00" > 11/14/24, 13:43 </span>
-
Garvin Hicking changed Related to #104786 <span data-processor="relativetime" data-value="2024-11-14T13:43:58+00:00" > 11/14/24, 13:43 </span>
-
Garvin Hicking commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2024-11-14T13:49:06+00:00" > 11/14/24, 13:49 </span> -
Gerrit Code Review pushed patch set 1 for main to change 86989 status
Needs FeedbackUnder Review <span data-processor="relativetime" data-value="2024-11-14T14:15:01+00:00" > 11/14/24, 14:15 </span> -
André Buchmann commented and changed description <span data-processor="relativetime" data-value="2024-11-14T14:17:55+00:00" > 11/14/24, 14:17 </span>
@ghi Haven’t tried that yet. Upated the description with a link to the full example.
Patch has been created, but I’ll give it a try. -
Simon Praetorius commented <span data-processor="relativetime" data-value="2024-11-14T14:46:47+00:00" > 11/14/24, 14:46 </span>
You can also have a look at the latest version of this patch, which already uses the invoker: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83718
-
André Buchmann commented <span data-processor="relativetime" data-value="2024-11-14T15:11:02+00:00" > 11/14/24, 15:11 </span>
Heyho @ghi Using the invoker prevents the array key warnings.
Here are both ways configured that they do not need the patch:
The invoker way:
$content = $view->getRenderingContext()->getViewHelperInvoker()->invoke( CObjectViewHelper::class, [ 'typoscriptObjectPath' => $blockType, 'data' => $data->getRawRecord()->toArray(), 'context' => $context, 'table' => 'tt_content', ], $subView->getRenderingContext(), );The resolver way:
$cObjectViewHelper = $view->getRenderingContext()->getViewHelperResolver()->createViewHelperInstance('f', 'cObject'); $cObjectViewHelper->setArguments([ 'typoscriptObjectPath' => $blockType, 'data' => $data->getRawRecord()->toArray(), 'table' => 'tt_content', 'currentValueKey' => null, // prevent array key warning 'context' => $context, ]); $cObjectViewHelper->setRenderingContext($subView->getRenderingContext()); $content = $cObjectViewHelper->render();—-
Bottom line: You think there is no need to add the null coalescing operator to the optional arguments? (see patch)
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2024-11-14T16:39:45+00:00" > 11/14/24, 16:39 </span>
Personally, yes, I’d follow Simons lead here and would say that the Invoker way is the suggested way to approach it, allowing the Core for future flexibility. While adding array checks in there would help your case, I think it would make the code a bit more “heavy” and extra weight (albeit only little).
So if you’re fine with it I would prefer to close the issue, yes. Thanks so much for adding in the resulting code that you worked out, and for offering the patch in first place! :)
-
André Buchmann commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2024-11-14T16:54:43+00:00" > 11/14/24, 16:54 </span>s2b andghi thx for pointing out the better solution.I abandon the patch and close the issue.
Have a nice day.
Possibly I’d argue that if you pass “raw” arguments and use the ViewHelper as API (which it isn’t intended to be) you would need to route all arguments to the setArguments() call.
Instead of wiring this by hand you probably should better use the
ViewHelperInvoker->invoke()method to call another ViewHelper, have you tried that?