Customising the Schema for Attributes
Note
The schema manager is implemented from version 2.3.
Database properties for attributes are manipulated via the schema manager — see Schema Manager for more details — and not via DCA customisation. Changes are checked and applied during the database migration, which can be triggered via the Contao Manager or the command line.
The following example changes the field for the long text attribute vita in the model mm_employees from TEXT (65535) to MEDIUMTEXT (16777215) — see Doctrine and Github.
1<?php
2// src/SchemaManager/SchemaManager.php
3namespace App\SchemaManager;
4
5use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
6use MetaModels\Information\MetaModelCollectionInterface;
7use MetaModels\Schema\Doctrine\DoctrineSchemaGeneratorInterface;
8use MetaModels\Schema\Doctrine\DoctrineSchemaInformation;
9
10#[DoctrineSchemaProvider(-20)]
11final class SchemaManager implements DoctrineSchemaGeneratorInterface
12{
13 public function generate(DoctrineSchemaInformation $schema, MetaModelCollectionInterface $collection): void
14 {
15 if (!$schema->getSchema()->hasTable('mm_employees')) {
16 return;
17 }
18
19 $table = $schema->getSchema()->getTable('mm_employees');
20
21 $table->getColumn('vita')->setLength(AbstractMySQLPlatform::LENGTH_LIMIT_MEDIUMTEXT);
22 }
23}
If you cannot or do not want to use the DoctrineSchemaProvider attribute for
registration, an alternative is to register via services.yml.
1# config/services.yml
2services:
3 App\SchemaManager\SchemaManager:
4 tags:
5 - { name: 'metamodels.schema-generator.doctrine', priority: -20 }
To verify that your own schema manager has been registered and loaded, use the console:
php vendor/bin/contao-console debug:container
More information on “Registering Services”.