Sylius Stack
  • Sylius Stack Documentation
  • Getting started
  • Cookbook
    • How to customize your admin panel
      • Basic operations
      • Customizing your grids
      • Customizing the logo
      • Customizing the menu
      • Configuring the security access
      • Customizing the page titles
    • How to use in a DDD architecture
      • Architecture overview
      • Resource configuration
      • Basic operations
      • Operation using a grid
  • Admin UI
    • Getting started
  • Bootstrap Admin UI
    • Getting started
  • Resource
    • Resource Bundle documentation
      • Installation
      • Create new resource
      • Configure your resource
      • Configure your operations
      • Validation
      • Redirect
      • Resource factories
      • Providers
      • Processors
      • Responders
      • Legacy Resource Documentation
        • Configuration
        • Services
        • Routing
        • Forms
        • Getting a Single Resource
        • Getting a Collection of Resources
        • Creating Resources
        • Updating Resources
        • Deleting Resources
        • Configuring a state machine
        • Configuration Reference
  • Grid
    • Grid Bundle documentation
      • Installation
      • Creating your first grid
      • Configuring Fields
      • Field types
      • Creating a custom Field Type
      • Creating a custom Action
      • Creating a custom Bulk Action
      • Filters
      • Creating a custom Filter
      • Advanced configuration
      • Configuration Reference
  • 🍀Twig Extra
    • Getting started
  • 🌱Twig Hooks
    • Getting started
    • Passing data to your hookables
    • Making your hookables configurable
    • Autoprefixing feature
    • Composable Layouts with a predictable structure
    • Advanced
      • Ergonomic work with hooks
      • Metadata objects
      • Multiple hooks inside a single template
      • Overriding hookables
Powered by GitBook
On this page
  • Default redirections
  • Custom redirection
  • Pass arguments to your redirection
  1. Resource
  2. Resource Bundle documentation

Redirect

PreviousValidationNextResource factories

Last updated 1 month ago

After that an action has been performed, the operation can be redirected to another operation.

Default redirections

Redirections are configured on your operations with these default behaviours.

Operation
Redirection

create

show if exists, otherwise index

update

show if exists, otherwise index

delete

index

bulk_delete

index

Custom redirection

For example, let's configure a custom redirection to create & update operations.

src/Entity/Book.php

declare(strict_types=1);

namespace App\Entity;

use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Update;
use Sylius\Resource\Model\ResourceInterface;

#[AsResource(
    operations: [
        new Create(
            redirectToRoute: 'app_book_update',
        ),
        new Update(
            redirectToRoute: 'app_book_update',
        ),
    ],
)
class Book implements ResourceInterface
{
}

After adding or editing a book, it will be redirected to the edition page of a book.

Pass arguments to your redirection

You can pass arguments to your redirection method.

3 variables are available:

  • resource: to retrieve data from the instantiated resource

  • {name_of_your_resource}: If your resource is a book instance, it will be also available as book variable

  • request: to retrieve data from the request via Symfony\Component\HttpFoundation\Request

As an example, let's redirect a book creation to the author details page of the created book.

src/Entity/Book.php

declare(strict_types=1);

namespace App\Entity;

use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Model\ResourceInterface;

#[AsResource(
    operations: [
        new Create(
            redirectToRoute: 'app_author_show', 
            # You can use either the generic resource variable
            redirectArguments: ['id' => 'resource.getAuthor().getId()']
            # Or you can use the resource name
            redirectArguments: ['id' => 'book.getAuthor().getId()']
        ),
    ],
)
class Book implements ResourceInterface
{
}

It uses the component.

Symfony expression language
Default redirections
Custom redirection
Pass arguments to your redirection