Feature #4207

Make action argument optional in ActionViewHelpers

Added by Jeff Segars almost 6 years ago. Updated almost 5 years ago.

Status:Resolved Start date:2009-08-10
Priority:Should have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:-
Target version:-
Has patch:

Description

The action view helpers for links and URIs both require the action argument. These view helpers may be used to generate links within the same action and templates may be shared across actions via partials. Thus, it would be helpful for the action to be an option argument like the controller and other arguments.

4207.diff Magnifier (2.4 kB) Jeff Segars, 2009-08-10 01:37

History

#1 Updated by Jeff Segars almost 6 years ago

#2 Updated by Jochen Rau almost 6 years ago

  • Status changed from New to Accepted
  • Assigned To set to Bastian Waidelich

Hi Bastian. Could you please take care of this issue?

#3 Updated by Bastian Waidelich almost 6 years ago

Hi Jeff,

sorry for the delay, the optional action argument makes perfect sense!
Only, there is an "issues" with that:
If I'd leave away the action argument, I'd expect the resulting URI not to contain the action at all, resulting in a call to the configured default action of the current plugin..

Actually, that's how I just implemented it for the formViewHelper and Uri-/Link-ActionViewHelpers in http://forge.typo3.org/attachments/1553/3981_tx_fluid_adjustments_v1.patch

If we want it to work the way you describe (no action -> use the current action) we'd need to modify the UriBuilder:
From:

if ($actionName !== NULL) {
    $controllerArguments['action'] = $actionName;
}

To:
if ($actionName !== NULL) {
    $controllerArguments['action'] = $actionName;
} else {
    $controllerArguments['action'] = $this->request->getControllerActionName();
}

But I'm not sure if that really makes sense.. In the end you'd want to use the action link to create links to different actions?
Please correct me, if I'm missing something.

#4 Updated by Bastian Waidelich almost 6 years ago

  • Status changed from Accepted to Resolved
  • % Done changed from 0 to 100

Since r1180 action argument of action viewhelpers is optional.
If action is not specified, it won't appear in the resulting URI thus linking to the default action of the specified controller.

#5 Updated by Jeff Segars almost 6 years ago

Hey Bastian,
For some reason I didn't get a notification on your first reply. Sorry for now responding sooner.

In my case, I'm using partials and a page browser view helper to display the same results from several different actions. When I navigate through the page browser, it makes sense to keep the current action, no matter what that action is. Perhaps I can address this by assigning a variable for the current action rather than leaving it out completely.

For most cases, your solution certainly makes more sense.

Thanks,
Jeff

#6 Updated by Bastian Waidelich almost 6 years ago

Jeff Segars wrote:

Hey Jeff,

Sorry for now responding sooner.

No problem.

In my case, I'm using partials and a page browser view helper to display the same results from several different actions.

I see. It might work to set the action explicitly in your page browser view helper then.. Something like:

public function render(..., $action = NULL, ...) {
    if ($action === NULL) {
        $request = $this->controllerContext->getRequest();
        $action = $request->getControllerActionName();
    }
    ...

Perhaps I can address this by assigning a variable for the current action rather than leaving it out completely.

That's another solution. You can pass arguments to the partial like this:

<f:render partial="foo" arguments="{action: 'bar'}" />

For most cases, your solution certainly makes more sense.

Well, I've discussed it with Sebastian and Jochen and they think the same.

Thanks for the feedback

#7 Updated by Bastian Waidelich almost 6 years ago

  • Project changed from Extbase MVC Framework to TYPO3.Fluid
  • Category deleted (432)

Also available in: Atom PDF