Hello there!
I got a strange problem. I created a behavior what adds a default timezone-string (iana-code) to a entity-/db-field. Therefore, I added a “beforeSave()” method to the class and it works as expected through the application.
But when request came through the rest api (rest including friendsofcake/crud), the entity will tried to be saved, the behavior is called (initialize()-method of the behavior), but not the part with the logic (beforeSave), so the entity won’t have the timezone-string and thus, saving fails with a mysql-exception. No matter, what signature “beforeSave” is of, the method is never executed. The api-controller is empty as crud handles all logic.
Can sb. help me out? Thanks in advance.
class TagsController extends AppController
{
}
class TimezoneBehavior extends Behavior
{
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $object) {
die("I WON'T BE EXECUTED VIA REST API REQUEST");
foreach($this->_defaultConfig['fields'] as $field) {
$entity->set($field, $this->getTimezone());
}
}
}