Skip to content

Commit a144b10

Browse files
committed
Merge branch '5.0' into shopping-list
2 parents d214221 + 9a3b4e0 commit a144b10

File tree

5 files changed

+106
-8
lines changed

5 files changed

+106
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace App\Export\User;
10+
11+
use Ibexa\Contracts\Cdp\Export\User\AbstractUserItemProcessor;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
13+
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
14+
use Ibexa\Core\FieldType\Date\Value as DateValue;
15+
16+
final class DateOfBirthUserItemProcessor extends AbstractUserItemProcessor
17+
{
18+
public function __construct(
19+
private readonly string $dateOfBirthFieldIdentifier,
20+
string $userFieldTypeIdentifier
21+
) {
22+
parent::__construct($userFieldTypeIdentifier);
23+
}
24+
25+
protected function doProcess(array $processedItemData, Content $userContent): array
26+
{
27+
$userField = $this->getUserField($userContent);
28+
29+
if (null === $userField) {
30+
throw new InvalidArgumentException('$userContent', 'User content does not contain user field');
31+
}
32+
33+
$dateOfBirth = '';
34+
$dateOfBirthField = $userContent->getField($this->dateOfBirthFieldIdentifier);
35+
36+
if ($dateOfBirthField !== null
37+
&& $dateOfBirthField->value instanceof DateValue
38+
&& $dateOfBirthField->value->date !== null
39+
) {
40+
$dateOfBirth = $dateOfBirthField->value->date->format('Y-m-d');
41+
}
42+
43+
return array_merge(
44+
$processedItemData,
45+
[
46+
'date_of_birth' => $dateOfBirth,
47+
]
48+
);
49+
}
50+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"ibexa/share": "~5.0.x-dev",
8181
"ibexa/shopping-list": "~5.0.x-dev",
8282
"ibexa/phpstan": "~5.0.-dev",
83-
"deptrac/deptrac": "^3.0"
83+
"deptrac/deptrac": "^3.0",
84+
"ibexa/cdp": "~5.0.x-dev"
8485
},
8586
"scripts": {
8687
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",

docs/cdp/cdp_activation/cdp_data_export.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ There are two versions of this command `--draft/--no-draft`.
4545
The first one is used to send the test user data to the Data Manager.
4646
If it passes a validation test in the **Activation** section, use the latter one to send a full version.
4747

48+
You can extend exported user data with custom fields from your user content, such as date of birth, preferences, or other profile information.
49+
For more information, see [Data customization](cdp_data_customization.md#export-additional-user-data).
50+
4851
Next, go back to [[= product_name_cdp =]] and select **Validate & download**.
4952
If the file passes, you can see a confirmation message.
5053
Now, you can go to the **File mapping** section.
@@ -63,6 +66,9 @@ If you make any alterations, select the **Parse File** to generate columns with
6366
In the **Transform & Map** section you transform data and map it to a schema.
6467
At this point, you can map **email** to **email** and **id** to **integer** fields to get custom columns.
6568

69+
If you have [extended user data export with custom fields](cdp_data_customization.md#export-additional-user-data), those fields appear as additional columns in this section.
70+
Make sure to add them to your schema in Raptor so they can be used for segmentation and personalization.
71+
6672
Next, select **Create schema based on the downloaded columns**.
6773
It moves you to Schema Creator.
6874
There, choose **PersonalData** as a parent and name the schema.

docs/cdp/cdp_data_customization.md

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,55 @@ edition: experience
55

66
# Data customization
77
8-
You can customize content and product data exported to CDP and you can control what field type information you want to export.
8+
You can customize user, content, and product data exported to CDP and you can control what field type information you want to export.
99
By default, custom field types have basic export functionality.
1010
It casts their `Value` object to string, thanks to `\Stringable` implementation.
1111
12+
## Export additional user data
13+
14+
You can extend user data exported to CDP by attaching custom information, for example user content fields or user preferences.
15+
Use it for advanced customer segmentation and personalization in marketing campaigns.
16+
17+
To add custom data to user exports, create a class that extends [`\Ibexa\Contracts\Cdp\Export\User\AbstractUserItemProcessor`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Cdp-Export-User-AbstractUserItemProcessor.html) and implement the `doProcess()` method.
18+
The base class handles user field validation and provides helper methods for working with user content.
19+
20+
The following example adds a custom date of birth field to the exported data:
21+
22+
``` php
23+
[[= include_file('code_samples/cdp/date_of_birth_export/src/Export/User/DateOfBirthUserItemProcessor.php') =]]
24+
```
25+
26+
Register your processor as a Symfony service and tag it with `ibexa.cdp.export.user.item_processor`:
27+
28+
``` yaml
29+
App\Export\User\DateOfBirthUserItemProcessor:
30+
parent: Ibexa\Contracts\Cdp\Export\User\AbstractUserItemProcessor
31+
arguments:
32+
$dateOfBirthFieldIdentifier: 'date_of_birth'
33+
tags:
34+
- { name: 'ibexa.cdp.export.user.item_processor', priority: 100 }
35+
```
36+
37+
The `priority` parameter controls the order of execution when multiple processors are registered.
38+
Higher priority values run first.
39+
Your custom processor can modify the data returned from the previous processors, for example by adding new entries or modifying the existing ones.
40+
41+
The exported user data includes your custom fields:
42+
43+
```json
44+
{
45+
"date_of_birth": "2000-01-01",
46+
"id": 1,
47+
"login": "example",
48+
"email": "example@example.org",
49+
"name": "John Doe",
50+
}
51+
```
52+
1253
## Export field types
1354
1455
Field types are exported with metadata, for example, ID, field definition name, type, or value.
15-
You can also provide your own `\Ibexa\Contracts\Cdp\Export\Content\FieldProcessorInterface` instance to extend metadata.
56+
You can also provide your own [`\Ibexa\Contracts\Cdp\Export\Content\FieldProcessorInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Cdp-Export-Content-FieldProcessorInterface.html) instance to extend metadata.
1657
The provided implementation has to be defined as a service and tagged with `ibexa.cdp.export.content.field_processor`.
1758
Additionally, you can specify `priority` to override the default behavior.
1859
All system Field Processors use `-100` priority, and any higher priority value overrides them.
@@ -47,7 +88,7 @@ You can only use scalar values.
4788
4889
You can provide your own CDP export functionality by using one of the system Field Processors:
4990

50-
#### `\Ibexa\Cdp\Export\Content\FieldProcessor\SkippingFieldProcessor`.
91+
#### `\Ibexa\Cdp\Export\Content\FieldProcessor\SkippingFieldProcessor`
5192
5293
It results in the field type being excluded from the exported payload.
5394
To avoid adding the field type data to the payload, register a new service as follows:
@@ -64,7 +105,7 @@ custom_fieldtype.cdp.export.field_processor:
64105
65106
## Export field type values
66107
67-
To customize export of field type values, provide your own `\Ibexa\Contracts\Cdp\Export\Content\FieldValueProcessorInterface` instance.
108+
To customize export of field type values, provide your own [`\Ibexa\Contracts\Cdp\Export\Content\FieldValueProcessorInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Cdp-Export-Content-FieldValueProcessorInterface.html) instance.
68109
New implementation has to be registered as a service manually or by using autoconfiguration.
69110
The service has to use the tag `ibexa.cdp.export.content.field_value_processor`.
70111
You can also provide `priority` property to override other Field Value Processors.
@@ -85,7 +126,7 @@ This Processor is a default one, as long as no other Processor with higher prior
85126
86127
#### `\Ibexa\Cdp\Export\Content\FieldValueProcessor\JsonHashFieldValueProcessor`
87128
88-
This Processor generates JSON data from hash representation of the field type (it uses `\Ibexa\Contracts\Core\FieldType\FieldType::toHash` method).
129+
This Processor generates JSON data from hash representation of the field type (it uses [`\Ibexa\Contracts\Core\FieldType\FieldType::toHash`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-FieldType-FieldType.html#method_toHash) method).
89130

90131
!!! caution
91132

@@ -101,4 +142,4 @@ custom_fieldtype.cdp.export.field_processor:
101142
$fieldTypeIdentifier: custom_fieldtype
102143
tags:
103144
- { name: 'ibexa.cdp.export.content.field_value_processor', priority: 0 }
104-
```
145+
```

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ INHERIT: plugins.yml
33
site_name: Developer Documentation
44
repo_url: https://github.com/ibexa/documentation-developer
55
site_url: https://doc.ibexa.co/en/latest/
6-
copyright: "Copyright 1999-2024 Ibexa AS and others"
6+
copyright: "Copyright 1999-2026 Ibexa AS and others"
77
validation:
88
omitted_files: warn
99
absolute_links: relative_to_docs

0 commit comments

Comments
 (0)