sulu-workshop icon indicating copy to clipboard operation
sulu-workshop copied to clipboard

12 - Add a location filter to the events overview page

Open luca-rath opened this issue 4 years ago • 4 comments

Add a location filter to the events overview page

Goal

After adding an association between our Location entity and our Event entity in the last assignment, we can now easily query events for a specific location. We want to make use of this by adding a location filter to the events overview page of our website.

Steps

  • Create a new content controller App\Controller\EventOverviewController
  • Remove the events property from the event_overview template
  • Use the newly created App\Controller\EventOverviewController in your event_overview template
  • Use the EventRepository to load events in your EventOverviewController
  • Use the LocationRepository to load locations in your EventOverviewController
  • Pass the loaded locations and events to your Twig template
  • Render a form with a location dropdown in your templates/events/index.html.twig
  • Add a filterByLocationId method to your App\Repository\EventRepository
  • Call the filterByLocationId method with the submitted value in your EventOverviewController

Hints

More Information

Links

luca-rath avatar Jul 07 '20 10:07 luca-rath

Guys, is this supposed to work properly because I cannot get it to work at all and I am an experienced dev. I tried this https://docs.sulu.io/en/2.4/cookbook/custom-controller.html but to no avail and am getting Cannot autowire argument $structure of "App\Controller\Website\EventOverviewController::indexAction()": it references interface "Sulu\Component\Content\Compat\StructureInterface" but no such service exists. Did you create a class that implements this interface?

costeaalex avatar Apr 11 '22 18:04 costeaalex

@costeaalex the Structure is no service this is a request attribute set by the content route provider. The error you are experience is mostly done if you try to register a route for a content controller, but content controller do not have a route as they are called by the dynamic route provider, which calls the controller based on saved pages and the pages template.

alexander-schranz avatar Apr 12 '22 08:04 alexander-schranz

@costeaalex the Structure is no service this is a request attribute set by the content route provider. The error you are experience is mostly done if you try to register a route for a content controller, but content controller do not have a route as they are called by the dynamic route provider, which calls the controller based on saved pages and the pages template.

I figured it out eventually, thanks. I think what would be helpful though is to offer the preferred solution to these problems as well so that people less experienced manage to get through it in a reasonable time span ;). Thanks for the input. You will probably be hearing from me for some consultancy and if we adopt the CMS we will contribute :P.

costeaalex avatar Apr 12 '22 17:04 costeaalex

@costeaalex If there is anything we can improve in the documentation, we are happy for any pul request there: https://docs.sulu.io/en/2.4/cookbook/custom-controller.html. Happy to hear you give sulu a try, you can reach us over our website or our slack channel for any questions.

alexander-schranz avatar Apr 12 '22 17:04 alexander-schranz