Symfony MakerBundle integration - adamwojs/formatted-textline GitHub Wiki
Integration with Symfony MakerBundle speeds up time needed to implement your custom field type based on provided abstractions.
make:ibexa:textline-field-type
allows to scaffold new field type based on AdamWojs\IbexaFormattedTextLineBundle\FieldType\FormattedTextLine\Type
.
Description:
Creates a new Ibexa Text Line field type
Usage:
make:ibexa:textline-field-type [options] [--] <name>
Arguments:
name field type name e.g. Color
Options:
--identifier=IDENTIFIER field type identifier e.g. ezcolor
--siteaccess[=SITEACCESS] SiteAccess to use for operations. If not provided, default siteaccess will be used
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The Environment name. [default: "dev"]
--no-debug Switch off debug mode.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
First add Symfony MakerBundle to your project, if you haven't done this before. Run
composer require symfony/maker-bundle --dev
and then enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:
<?php
return [
// ...
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
];
Now you can create field type using:
php bin/console make:ibexa:textline-field-type PostalCode
This command will generate the following files:
- src/FieldType/PostalCode/Type.php
- src/FieldType/PostalCode/Format.php
- config/services/fieldtype/postalcode.yaml
<?php
declare(strict_types=1);
namespace App\FieldType\PostalCode;
use AdamWojs\IbexaFormattedTextLineBundle\FieldType\FormattedTextLine\Type as FormattedTextLineType;
final class Type extends FormattedTextLineType
{
public function getFieldTypeIdentifier(): string
{
return 'postalcode';
}
}
<?php
declare(strict_types=1);
namespace App\FieldType\PostalCode;
use AdamWojs\IbexaFormattedTextLineBundle\FieldType\FormattedTextLine\Format as FormatInterface;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
final class Format implements FormatInterface
{
public function validate(FieldDefinition $fieldDefinition, string $text): bool
{
return true;
}
public function getMask(FieldDefinition $fieldDefinition): ?string
{
return null;
}
public function getExamples(FieldDefinition $fieldDefinition): array
{
return [];
}
}
services:
_defaults:
autowire: true
autoconfigure: true
public: false
app.field_type.postalcode:
class: App\FieldType\PostalCode\Type
arguments:
$format: '@app.field_type.postalcode.format'
tags:
- { name: ezplatform.field_type, alias: postalcode }
app.field_type.postalcode.format:
class: App\FieldType\PostalCode\Format
app.field_type.postalcode.converter:
class: AdamWojs\IbexaFormattedTextLineBundle\Persistence\Legacy\Converter\TextLineConverter
tags:
- { name: ezplatform.field_type.legacy_storage.converter, alias: postalcode }
app.field_type.postalcode.indexable:
class: AdamWojs\IbexaFormattedTextLineBundle\FieldType\FormattedTextLine\SearchField
tags:
- { name: ezplatform.field_type.indexable, alias: postalcode }
app.field_type.postalcode.form_mapper.value:
class: AdamWojs\IbexaFormattedTextLineBundle\Form\Mapper\FormattedTextLine\FieldValueFormMapper
arguments:
$format: '@app.field_type.postalcode.format'
tags:
- { name: ezplatform.field_type.form_mapper.value, fieldType: postalcode }
(!) Please remember to import generated services definition in your config/service.yaml
:
imports:
- { resource: services/fieldtype/** }