-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed as not planned
Labels
Milestone
Description
Hi everyone
Please clarify the documentation for Transforming Request Data into Entity Properties. Currently it's unclear how to get the custom fields from Behaviour into Entities of the Table said Behaviour is attached to. It only shows a small snippet out of context.
I created a behaviour and copied that snipet from documentation.
<?php
namespace MyPlugin\Model\Behavior;
class SluggableBehavior extends \Cake\ORM\Behavior implements \Cake\ORM\PropertyMarshalInterface
{
public function initialize(array $config): void
{
// Confirm SluggableBehavior is connected and loaded
debug([
'$this' => $this,
'$config' => $config,
]);
parent::initialize($config);
}
public function buildMarshalMap(\Cake\ORM\Marshaller $marshaller, array $map, array $options): array
{
return [
'slug' => function ($value, $entity) {
// Transform the value as necessary
return '123';
}
];
}
public function slug($entity)
{
return $entity->{$this->getDisplayField()};
}
}
When I call ->slug
on an entity, I get a null
. I'm clearly missing something, but I can't understand what from the documentation.
Additional resources I checked: