Skip to content

Comments

Documented adding custom fields to CDP export#3061

Open
mnocon wants to merge 4 commits into4.6from
custom-cdp-exporter
Open

Documented adding custom fields to CDP export#3061
mnocon wants to merge 4 commits into4.6from
custom-cdp-exporter

Conversation

@mnocon
Copy link
Contributor

@mnocon mnocon commented Feb 12, 2026

Target: 4.6, 5.0

The doc is missing the extension points introduced in https://github.com/ibexa/corporate-account/pull/174 and https://github.com/ibexa/cdp/pull/11

This PR focuses on showing how to add custom fields to user data export, as this is something that has been raised by partners.

Tested locally:

~/Desktop/Sites/4.6 main !5028 ?140 ❯ php bin/console ibexa:cdp:stream-user-data -vv --draft --user-content-type user                                                                 24.4.0 14:32:09
Data will be streamed as a draft
Stream ID: 00000000-00000000-00000000-00000000
array(2) {
  [0]=>
  array(6) {
    ["date_of_birth"]=>
    string(0) ""
    ["companies"]=>
    array(0) {
    }
    ["id"]=>
    int(10)
    ["login"]=>
    string(9) "anonymous"
    ["email"]=>
    string(22) "anonymous@link.invalid"
    ["name"]=>
    string(14) "Anonymous User"
  }
  [1]=>
  array(6) {
    ["date_of_birth"]=>
    string(10) "2026-02-17"
    ["companies"]=>
    array(0) {
    }
    ["id"]=>
    int(14)
    ["login"]=>
    string(5) "admin"
    ["email"]=>
    string(18) "admin@link.invalid"
    ["name"]=>
    string(18) "Administrator User"
  }
}

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Preview of modified files

Preview of modified Markdown:

@mnocon mnocon force-pushed the custom-cdp-exporter branch 2 times, most recently from 9c409da to b28445e Compare February 13, 2026 08:15
@mnocon mnocon force-pushed the custom-cdp-exporter branch from b28445e to f708502 Compare February 13, 2026 08:38
@mnocon mnocon marked this pull request as ready for review February 13, 2026 13:33
@mnocon mnocon requested a review from a team February 13, 2026 13:47
Copy link
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@mnocon mnocon requested a review from a team February 20, 2026 13:14
@ibexa-workflow-automation-1 ibexa-workflow-automation-1 bot requested review from adriendupuis, dabrt and julitafalcondusza and removed request for a team February 20, 2026 13:14

The `priority` parameter controls the order of execution when multiple processors are registered.
Higher priority values run first.
Your custom processor merges data with `$processedItemData` from previous processors, allowing you to chain multiple processors together.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As

        return array_merge(
            $processedItemData,
            [
                'date_of_birth' => $dateOfBirth,
            ]
        );

is equivalent to

$processedItemData['date_of_birth'] = $dateOfBirth;
return $processedItemData;

there might be a simpler way to tell things (even if array_merge is probably more readable when a huge data array is added):

Suggested change
Your custom processor merges data with `$processedItemData` from previous processors, allowing you to chain multiple processors together.
Your custom processor adds data to the previous processors result and returns the whole, allowing to chain multiple processors together.

I guess you could even have a processor than transform previous data (for example $processedItemData['date_of_birth'] = $this->formatDate($processedItemData['date_of_birth'])).

@github-actions
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/cdp/date_of_birth_export/src/Export/User/DateOfBirthUserItemProcessor.php


code_samples/cdp/date_of_birth_export/src/Export/User/DateOfBirthUserItemProcessor.php

docs/cdp/cdp_data_customization.md@22:``` php
docs/cdp/cdp_data_customization.md@23:[[= include_file('code_samples/cdp/date_of_birth_export/src/Export/User/DateOfBirthUserItemProcessor.php') =]]
docs/cdp/cdp_data_customization.md@24:```

001⫶<?php
002⫶
003⫶/**
004⫶ * @copyright Copyright (C) Ibexa AS. All rights reserved.
005⫶ * @license For full copyright and license information view LICENSE file distributed with this source code.
006⫶ */
007⫶declare(strict_types=1);
008⫶
009⫶namespace App\Export\User;
010⫶
011⫶use Ibexa\Contracts\Cdp\Export\User\AbstractUserItemProcessor;
012⫶use Ibexa\Contracts\Core\Repository\Values\Content\Content;
013⫶use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
014⫶use Ibexa\Core\FieldType\Date\Value as DateValue;
015⫶
016⫶final class DateOfBirthUserItemProcessor extends AbstractUserItemProcessor
017⫶{
018⫶ private string $dateOfBirthFieldIdentifier;
019⫶
020⫶ public function __construct(
021⫶ string $dateOfBirthFieldIdentifier,
022⫶ string $userFieldTypeIdentifier
023⫶ ) {
024⫶ $this->dateOfBirthFieldIdentifier = $dateOfBirthFieldIdentifier;
025⫶
026⫶ parent::__construct($userFieldTypeIdentifier);
027⫶ }
028⫶
029⫶ protected function doProcess(array $processedItemData, Content $userContent): array
030⫶ {
031⫶ $userField = $this->getUserField($userContent);
032⫶
033⫶ if (null === $userField) {
034⫶ throw new InvalidArgumentException('$userContent', 'User content does not contain user field');
035⫶ }
036⫶
037⫶ $dateOfBirth = '';
038⫶ $dateOfBirthField = $userContent->getField($this->dateOfBirthFieldIdentifier);
039⫶
040⫶ if ($dateOfBirthField !== null
041⫶ && $dateOfBirthField->value instanceof DateValue
042⫶ && $dateOfBirthField->value->date !== null
043⫶ ) {
044⫶ $dateOfBirth = $dateOfBirthField->value->date->format('Y-m-d');
045⫶ }
046⫶
047⫶ return array_merge(
048⫶ $processedItemData,
049⫶ [
050⫶ 'date_of_birth' => $dateOfBirth,
051⫶ ]
052⫶ );
053⫶ }
054⫶}

Download colorized diff

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants