Version

Documentation » Timeline Bundle

2. Configuration »

« Timeline Bundle

This Page

2. Configuration »

« Timeline Bundle

1. Installation

The easiest way to install SonataTimelineBundle is to require it with Composer:

composer require sonata-project/timeline-bundle

Alternatively, you could add a dependency into your composer.json file directly.

Note

This will install the SpyTimelineBundle, too.

Now, enable the bundle in bundles.php file:

// config/bundles.php

return [
    // ...
    Sonata\CoreBundle\SonataCoreBundle::class => ['all' => true],
    Sonata\TimelineBundle\SonataTimelineBundle::class => ['all' => true],
    Spy\TimelineBundle\SpyTimelineBundle::class => ['all' => true],
];

1.1. Configuration

1.1.1. SpyTimelineBundle Configuration

# config/packages/spy_timeline.yaml

spy_timeline:
    drivers:
        orm:
            object_manager: doctrine.orm.entity_manager
            classes:
                query_builder: ~ # Spy\TimelineBundle\Driver\ORM\QueryBuilder\QueryBuilder
                timeline:         App\Application\Sonata\TimelineBundle\Entity\Timeline
                action:           App\Application\Sonata\TimelineBundle\Entity\Action
                component:        App\Application\Sonata\TimelineBundle\Entity\Component
                action_component: App\Application\Sonata\TimelineBundle\Entity\ActionComponent

    filters:
        data_hydrator:
            priority:          20
            service:           spy_timeline.filter.data_hydrator
            filter_unresolved: false
            locators:
                - spy_timeline.filter.data_hydrator.locator.doctrine_orm

1.1.2. SonataTimelineBundle Configuration

# config/packages/sonata_timeline.yaml

sonata_timeline:
    manager_type: orm
    class:
        timeline:         '%spy_timeline.class.timeline%'
        action:           '%spy_timeline.class.action%'
        component:        '%spy_timeline.class.component%'
        action_component: '%spy_timeline.class.action_component%'
        user:             '%sonata.user.admin.user.entity%'

1.2. Extend the Bundle

At this point, the bundle is usable, but not quite ready yet. You need to generate the correct entities for the timeline:

bin/console sonata:easy-extends:generate SonataTimelineBundle --dest=src --namespace_prefix=App

Note

If you are not using Symfony Flex, use command without --namespace_prefix=App.

With provided parameters, the files are generated in src/Application/Sonata/TimelineBundle.

Note

The command will generate domain objects in an App\Application namespace. So you can point entities associations to a global and common namespace. This will make entities sharing very easily as your models are accessible through a global namespace. For instance the action will be App\Application\Sonata\TimelineBundle\Entity\Action.

Now, add the new Application Bundle into the bundles.php:

// config/bundles.php

return [
    // ...
    App\Application\Sonata\TimelineBundle\ApplicationSonataTimelineBundle::class => ['all' => true],
];

1.2.1. Update the Database Schema

bin/console doctrine:schema:update --force

1.3. Enable the Timeline Block

  • YAML
    # config/packages/sonata_admin.yaml
    
    sonata_admin:
        dashboard:
            blocks:
                - { position: center, type: sonata.timeline.block.timeline, settings: { context: SONATA_ADMIN, max_per_page: 25 }}
    
  • YAML
    # config/packages/sonata_block.yaml
    
    sonata_block:
        blocks:
            sonata.timeline.block.timeline:
    

1.4. Edit the Timeline Block

Create a new template file here, based on the default timeline.html.twig

src/Application/TimelineBundle/Resources/views/Block/timeline.html.twig

And then edit the sonata_admin definition here, adding the “template” option.

# config/packages/sonata_admin.yaml

sonata_admin:
    dashboard:
        blocks:
            - { position: center, type: sonata.timeline.block.timeline, settings: { template: '@ApplicationTimeline/Block/timeline.html.twig', context: SONATA_ADMIN, max_per_page: 25 }}

And now, you’re good to go !

Found a typo? Something is wrong in this documentation? Just fork and edit it!