SyliusResourceBundle
SyliusResourceBundle copied to clipboard
ResourceController: Dispatch event with data before giving it to `render()`
Here is the showAction from the ResourceController:
public function showAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::SHOW);
$resource = $this->findOr404($configuration);
$event = $this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource);
$eventResponse = $event->getResponse();
if (null !== $eventResponse) {
return $eventResponse;
}
if ($configuration->isHtmlRequest()) {
return $this->render($configuration->getTemplate(ResourceActions::SHOW . '.html'), [
'configuration' => $configuration,
'metadata' => $this->metadata,
'resource' => $resource,
$this->metadata->getName() => $resource,
]);
}
return $this->createRestView($configuration, $resource);
}
What if it looked something like this:
public function showAction(Request $request): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
$this->isGrantedOr403($configuration, ResourceActions::SHOW);
$resource = $this->findOr404($configuration);
$event = $this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $resource);
$eventResponse = $event->getResponse();
if (null !== $eventResponse) {
return $eventResponse;
}
$data = [
'configuration' => $configuration,
'metadata' => $this->metadata,
'resource' => $resource,
$this->metadata->getName() => $resource,
];
$event = $this->eventDispatcher->dispatch(..., $data);
if ($configuration->isHtmlRequest()) {
return $this->render($configuration->getTemplate(ResourceActions::SHOW . '.html'), $event->getData());
}
return $this->createRestView($configuration, $resource);
}
This would allow users to provide more data to the template without having to override ResourceController or using Twig functions to get what they need.
What version of Aleph are you using? I think this particular issue was fixed since 0.4.5-alpha1
It looks like this was fixed in https://github.com/ztellman/aleph/pull/337, since 0.4.5-alpha1 as @gsnewmark says.
This makes aleph client unusable on JVM 9/10 which I consider serious. I can use :jvm-opts ["--add-modules" "java.xml.bind”] option in project.clj, but I would like the bug to be fixed
I don't think this was your intent, but these comments come across as demanding. Something like this could have been a better way to state your issue:
When upgrading my JVM to 10.0.1 (or even 9.0.1) I get an error about the javax.xml.bind.DatatypeConverter class being missing. [Add stack trace here] Adding
:jvm-opts ["--add-modules" "java.xml.bind”]to my project.clj adds that class back, but if it's possible to update aleph to not depend on this module, that would be easier to use.
I am using 0.4.5-alpha6
Based on your stacktrace it's problem in http-kit, not Aleph :thinking:
Caused by:
java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter, compiling:(org/httpkit/client.clj:1:1)
(source here is org/httpkit/client.clj)
Do you have both these libs on your classpath?
Sorry for this thread. httpkit was in project.clj You can close the ticket
@lyriccoder http-kit 2.3.0 resolves the JDK 9 issue.