Bruna fixes her menu

Exercise 3 of 6 in chapter 3 · 180 XP · 5 objectives checked by tests

Topics covered: Edit formRoute {slug:plat}

A typo on the menu: the “Elven Mushroom Pie” has become the “Elven Mushrom Pie”. And the stew's price has to go up (the grumpy dwarf is demanding a raise). Bruna wants to be able to edit a dish without going through the console.

Good news: PlatType works just as well for creating as for editing. You only need to bind it to an existing dish.

Your mission

  1. Add a modifierPlat() (edit dish) action to CuisineController on /kitchen/dish/{slug}/edit (route app_modifier_plat):
    • the dish is found from the slug in the URL (404 if it does not exist);
    • the PlatType form is displayed, prefilled;
    • if it is submitted and valid: save, add the flash message “The dish has been updated.”, then redirect to the dish page.
  2. Write the cuisine/modifier.html.twig template, with a “Save” button.
  3. On a dish page, add an “Edit” link.

The slug does not change when the name changes: links to the dish page that have already been shared must stay valid.

Reminder

An object loaded from the database is tracked by Doctrine: on flush(), its changes are written. persist() is only for new objects.