Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Contributte Doctrine Extensions Atlantic18

Integration of Gedmo/DoctrineExtensions (Atlantic18) for Nette Framework.

Content

Installation

Install package using composer.

composer require nettrine/extensions-atlantic18

Register prepared compiler extension in your config.neon file.

extensions:
    nettrine.extensions.atlantic18: Nettrine\Extensions\Atlantic18\DI\Atlantic18BehaviorExtension

Note

This extension requires nettrine/dbal and nettrine/orm to be installed and configured.

Configuration

Listeners

By default, all listeners are disabled. Enable only the ones you need.

nettrine.extensions.atlantic18:
    loggable: false
    sluggable: false
    softDeleteable: false
    treeable: false
    blameable: false
    timestampable: false
    translatable: false
    uploadable: false
    sortable: false
    ipTraceable: false

Here is the list of all available options with their types.

nettrine.extensions.atlantic18:
    loggable: <bool>
    sluggable: <bool>
    softDeleteable: <bool>
    treeable: <bool>
    blameable: <bool>
    timestampable: <bool>
    translatable: <bool|structure>
    uploadable: <bool>
    sortable: <bool>
    ipTraceable: <bool|structure>

For example, enable timestampable and sluggable:

nettrine.extensions.atlantic18:
    timestampable: true
    sluggable: true

Tip

Take a look at more information in official Gedmo documentation:

Translatable

TranslatableListener has a complex configuration:

nettrine.extensions.atlantic18:
    translatable:
        translatable: cs_CZ
        default: en_US
        translationFallback: false
        persistDefaultTranslation: false
        skipOnLoad: false
Option Type Description
translatable string Current locale for translations
default string Default locale
translationFallback bool Use fallback locale if translation not found
persistDefaultTranslation bool Persist default locale translation
skipOnLoad bool Skip translations on entity load

Tip

Take a look at more information in official Gedmo documentation:

IpTraceable

IpTraceable requires client IP address:

nettrine.extensions.atlantic18:
    ipTraceable:
        ipValue: @Nette\Http\IRequest::getRemoteAddress()

Or provide a static IP:

nettrine.extensions.atlantic18:
    ipTraceable:
        ipValue: '127.0.0.1'

Tip

Take a look at more information in official Gedmo documentation:

Entity mapping

Gedmo 3.x uses PHP 8 attributes for entity mapping. No additional configuration is required.

<?php declare(strict_types = 1);

namespace App\Model\Database\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

#[ORM\Entity]
class Article
{

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private int $id;

    #[ORM\Column(type: 'string')]
    private string $title;

    #[ORM\Column(type: 'string', unique: true)]
    #[Gedmo\Slug(fields: ['title'])]
    private string $slug;

    #[ORM\Column(type: 'datetime')]
    #[Gedmo\Timestampable(on: 'create')]
    private \DateTime $createdAt;

    #[ORM\Column(type: 'datetime')]
    #[Gedmo\Timestampable(on: 'update')]
    private \DateTime $updatedAt;

}

For Loggable, Translatable, and Tree behaviors, you need to set up extra entity mapping:

nettrine.orm:
    entityManagerDecoratorClass: Nettrine\ORM\EntityManagerDecorator
    configuration:
        driver: pdo_pgsql
        ...

    dql:
        ...

services:
    # Register Gedmo entity paths
    nettrine.orm.xmlDriver:
        setup:
            - addPaths([%vendorDir%/gedmo/doctrine-extensions/src/Translatable/Entity])
            - addPaths([%vendorDir%/gedmo/doctrine-extensions/src/Loggable/Entity])
            - addPaths([%vendorDir%/gedmo/doctrine-extensions/src/Tree/Entity])

Examples

Tip

Take a look at more examples in contributte/doctrine.