Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Make it possible to assign variables to view #1199

Open
wants to merge 5 commits into
base: typo3-v12
Choose a base branch
from

Conversation

sypets
Copy link
Contributor

@sypets sypets commented Dec 10, 2024

In event FormControllerFormActionEvent, make it possible to assign variables to view.

Resolves: #1198

In event FormControllerFormActionEvent, make it possible to assign
variables to view.

Resolves: in2code-de#1198
@thomasrawiel
Copy link

I think you're missing the step, where you get the event's $view back to the controller.

I'd suggest just adding an array to the event for "additionalVariables" and assign those.

final class FormControllerFormActionEvent {
  ....
  protected array $additionalVariables = [];
  
  ...
  
  public function getAdditionalVariables(): array
  {
    return $this->additionalVariables;
  }
  
  public function setAdditionalVariables(array $additionalVariables): void
  {
    $this->additionalVariables = $additionalVariables;
  }
}
//keep this the same
$event = $this->eventDispatcher->dispatch(
            GeneralUtility::makeInstance(FormControllerFormActionEvent::class, $form, $this)
        );

...

$this->view->assignMultiple(
            array_merge(
                [
                    'form' => $form,
                    'ttContentData' => $this->contentObject->data,
                    'messageClass' => $this->messageClass,
                    'action' => ($this->settings['main']['confirmation'] ? 'checkConfirmation' : 'checkCreate'),
                ],
                $event->getAdditionalVariables() 
            )
        );

@sypets sypets marked this pull request as draft December 11, 2024 16:39
@sypets
Copy link
Contributor Author

sypets commented Dec 11, 2024

Objects should be automatically passed by reference, no? Unless there is a severe case of "Brett-vorm-Kopf" on my end. I admit, I did not test this yet.

Changing to "Draft", will test and make change as you suggested, if necessary.

@sypets
Copy link
Contributor Author

sypets commented Dec 11, 2024

I checked, it should be fine

image

@sypets sypets marked this pull request as ready for review December 11, 2024 18:24
@thomasrawiel
Copy link

thomasrawiel commented Dec 11, 2024

I see. However, I'm still wondering if you actually need the whole ViewInterface, when you "just want to pass some variables" in this case.

edit: No you're right, it's probably also more convenient if you can just use the interface methods

@sypets sypets force-pushed the make-possible-to-assign-var-to-view-in-FormControllerFormActionEvent branch from 32243c2 to 3721341 Compare December 11, 2024 21:02
@mschwemer mschwemer self-requested a review January 7, 2025 08:42
@mschwemer
Copy link
Collaborator

Looks good from reading. Need to test it, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to assign variables to view in FormControllerFormActionEvent
3 participants