Feature #9514

Support explicit Array Arguments for ViewHelpers

Added by Sebastian Kurfuerst almost 5 years ago. Updated about 4 years ago.

Status:New Start date:2010-08-30
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
Has patch:

Description

We have been brainstorming over some additions to fluid syntax.

  • Imagine you have a ViewHelper with the following Render Method signature:
    function render(array $bla)
  • then it would be very nice if one could write the following:
    <f:xy arr.someArrayKey="foo" /> // "foo" is not validated, as we do not have any more type information.
  • Additionally, one could override specific key/value pairs of array arguments:
    <f:xy arr="{myArray}" arr.someArrayKey="foo" /> // "foo" is merged into {myArray}

Additionally, one could register specific array keys, and validate them. Imagine the following argument registration:
$this->registerArgument('foo.bar', 'boolean', REQUIRED=TRUE);

  • Now, it is validated that foo.bar is a boolean value, which exists; so you would know that $this->arguments['foo']['bar'] is really a boolean and it is set.

What needs to be changed internally:

On compile time:

  • TemplateParser->abortIfUnregisteredArgumentsExist($expectedViewHelperArguments, $argumentsObjectTree);
    • if Argument name is "bla.blubb", check that either the argument "bla.blubb" or the argument "bla" has been explicitely registered (and "bla" is an array)
  • TemplateParser->abortIfRequiredArgumentsAreMissing($expectedViewHelperArguments, $argumentsObjectTree);
    • do not abort if "bla.blubb" is not registered, but "bla" is.

On run-time: Type checking

  • change validateArguments in AbstractVH
    1. MERGING von "arr.abcde" und "arr" (Punkt-Syntax überschreibt)
    2. VALIDIERUNG (von allen regeln) -> d.h. wenn es eine Regel "arr.abcde" gibt, dann wird geschaut ob es diesen Array Key gibt

Examples of possible usage

<f:widget.paginate objects="{posts}" configuration.position="top" configuration.itemsPerPage="3" configuration.linkCurrent="false" /> <==>
<f:widget.paginate objects="{posts}" configuration="{position: 'top', itemsPerPage: 3, linkCurrent: 'false'}" />

Shorthand Sxntax

Will work like the explicit syntax:
{f:widget.paginate(objects: posts, configuration.position: 'top')}

However, for Arrays, this is NOT ALLOWED: {foo: {bar: '123'}} {foo.bar: '123', foo: {bar: '123'}} < this should be forbidden!

History

#1 Updated by Sebastian Kurfuerst about 4 years ago

  • Tracker changed from Major Feature to Story

#2 Updated by Sebastian Kurfuerst about 4 years ago

  • Tracker changed from Story to Feature

Also available in: Atom PDF