Hello everyone,
I have two models Contents and Terms, where Contents HABTM Terms.
In my CreateContent
form, I have built a structure as shown in the following
part of the request->data
table
terms => [
columns' => [
'single_select' => [
'id' => '3'
]
],
'tags' => [
'unlimited_select' => [
'vocabulary_id' => '1',
'names' => 'tag2,another,war,tag1'
]
]
That is because there is the possibility of picking a term from a set of existing ones (using <select>
tag)
or typing terms (within an <input>
tag) which creates new ones.
Since that format is not following the CakePHP conventions I want to re-structure the data.
I tried to use the Model.beforeMarshal
event as indicated in the Modifying request data before building entities section on the Book but with no luck.
When I call the patchEntity($content, $this->request->getData(), ['associated' => ['Terms']])
method, the Terms are not patched at all. After digging and scratching a little bit the cakePHP code (classes Table
& Marshaller
I found out that the original data are passed to the corresponding methods marshal()
and _marshalAssociation()
.
Does the beforeMarshal()
modifies the actual data or not?
What am I missing in this context?
Thank you very much in advance
Chistos