ezsystems/ezplatform-content-forms
Ibexa Content Forms integrates Symfony Forms with Ibexa DXP (eZ Platform) Content and User objects in the Kernel, enabling form-based creation and editing. See Ibexa Repository docs and PHP API value objects for usage.
Installation:
composer require ezsystems/ezplatform-content-forms
Ensure you have Ibexa DXP installed as a dependency.
Enable the Bundle:
Add to config/bundles.php:
Ibexa\ContentForms\EzPlatformContentFormsBundle\EzPlatformContentFormsBundle::class => ['all' => true],
First Use Case: Create a custom form type for a content type. Example:
// src/Form/Type/MyContentTypeFormType.php
namespace App\Form\Type;
use Ibexa\ContentForms\EzPlatformContentFormsBundle\Form\Type\ContentTypeFormType;
use Symfony\Component\Form\AbstractType;
class MyContentTypeFormType extends AbstractType
{
public function getParent()
{
return ContentTypeFormType::class;
}
public function configureOptions(\Symfony\Component\OptionsResolver\OptionsResolver $resolver)
{
$resolver->setDefaults([
'content_type' => 'my_content_type_identifier',
]);
}
}
Routing:
Use the built-in routes for content editing (e.g., /content/edit/{contentId}). Configure in config/routes.yaml:
ezplatform_content_forms:
resource: "@EzPlatformContentFormsBundle/Resources/config/routing.yml"
Twig Integration:
Extend templates in templates/bundles/EzPlatformContentForms/ to customize rendering.
ContentTypeFormType or UserTypeFormType to customize fields:
class CustomArticleFormType extends ContentTypeFormType
{
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add('custom_field', TextType::class);
}
}
field_map option to override default field handling:
$resolver->setDefaults([
'field_map' => [
'title' => 'custom_title_field',
],
]);
$builder->add('price', MoneyType::class, [
'constraints' => [
new NotBlank(),
new Positive(),
],
]);
submit() in your form type to add logic:
public function submit(\Symfony\Component\Form\FormInterface $form, \Ibexa\Contracts\Core\Repository\Values\Content\Content $content)
{
$data = $form->getData();
// Custom logic (e.g., pre-save transformations)
parent::submit($form, $content);
}
TranslatableFieldType for multi-language fields:
$builder->add('description', TranslatableFieldType::class, [
'field_definition_identifier' => 'description',
]);
UserTypeFormType:
class CustomUserFormType extends UserTypeFormType
{
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add('department', EntityType::class, [
'class' => Department::class,
]);
}
}
ImageFieldType:
$builder->add('image', ImageFieldType::class, [
'required' => true,
'config' => [
'upload_dir' => '%kernel.project_dir%/public/uploads',
],
]);
DateFieldType or DateTimeFieldType with timezone support:
$builder->add('event_date', DateTimeFieldType::class, [
'widget' => 'single_text',
'input' => 'datetime',
'with_timezone' => true,
]);
ContentService to fetch/save content:
public function __construct(
private ContentService $contentService
) {}
public function saveContent(Content $content)
{
$this->contentService->saveContent($content);
}
$location = $this->locationService->createLocation($content, $parentLocation);
templates/bundles/EzPlatformContentForms/:
content/edit.html.twiguser/edit.html.twigez_content_form_row for field-specific styling.FormFactory to dynamically generate forms:
$form = $this->formFactory->createNamedBuilder(
'dynamic_form',
ContentTypeFormType::class,
$content,
[
'content_type' => $contentTypeIdentifier,
'field_map' => $customFieldMap,
]
);
ezplatform_content_forms.form.factory service to create forms programmatically.ezplatform_content_forms.form.pre_submit or ezplatform_content_forms.form.post_submit events.content_type option matches an existing Ibexa content type identifier.field_definition_identifier for each field (check Ibexa’s FieldDefinition repository).ContentService::hasAccess()).field_definition_identifier.FieldDefinition repository:
$fieldDef = $this->fieldDefinitionService->loadFieldDefinition($identifier);
ezplatform_content_forms.debug in config to log field mapping issues.translatable option in field_map:
'field_map' => [
'title' => [
'field_definition_identifier' => 'title',
'translatable' => false,
],
],
contentId or versionNo not casting to integers, causing errors.nodraft mode.ezplatform_content_forms.autosave.enabled = false in config.LocationService is used to handle location-specific logic (fixed in v1.3.12).ezdate fields.with_timezone: true and ensure server timezone matches expectations (fixed in v1.3.13).How can I help you explore Laravel packages today?