like a Penguin in Sahara
Announcement
Collapse
No announcement yet.
7.0x about value-objects
Collapse
X
-
Hello item ,
Trying to educate myself on what are "value objects" and how they work, ran into this article that might help
- Likes 1
-
Thanks Yuri,
i don't undertand all but with your guidance..
PHP Code:if ($data->dio_phone_mobile)
{
$phoneNumberGroup = $entity->getPhoneNumberGroup();
if (!$phoneNumberGroup->hasNumber($data->dio_phone_mobile))
{
$modifiedPhoneNumberGroup = $phoneNumberGroup
->withAdded( PhoneNumber::create($data->dio_phone_mobile)->withType('Mobile'));
$entity->setPhoneNumberGroup($modifiedPhoneNumberGroup);
$em->saveEntity($entity);
}
}
Last edited by item; 11-06-2021, 09:04 PM.
Leave a comment:
-
Value objects are immutable. https://en.wikipedia.org/wiki/Value_object.
Wrong:
PHP Code:$valueObject->withSomething($something);
Right:
PHP Code:$valueObject = $valueObject->withSomething($something);
https://docs.espocrm.com/development...#value-objects
- Likes 1
Leave a comment:
-
7.0x about value-objects
https://docs.espocrm.com/development...#value-objects
Hi,
i try .. but no luck (certainly because my english)
how i can "insert" phoneNumber in back-end
i have try many .. no luck
nothing is saved in entity
HTML Code:$group = $entity->getPhoneNumberGroup(); if ($data->phone_office && !$group->hasNumber($data->phone_office)) { $phone = PhoneNumber::create($data->phone_office); $phone->withType('Office'); $group->withAdded($phone); }elseif($data->phone_alternate && !$group->hasNumber($data->phone_alternate)) { $phone = PhoneNumber::create($data->phone_alternate); $phone->withType('Home'); $group->withAdded($phone); }elseif($data->dio_phone_mobile && !$group->hasNumber($data->dio_phone_mobile)) { $phone = PhoneNumber::create($data->dio_phone_mobile); $phone->withType('Mobile'); $group->withAdded($phone); } $valueMap = (new PhoneNumberGroupAttributeExtractor())->extract($group, 'phoneNumberData'); $GLOBALS['log']->warning('valueMap => ' .json_encode( $valueMap )); $GLOBALS['log']->warning('group => ' .json_encode( $group )); $GLOBALS['log']->warning('phone => ' .json_encode( $phone )); //$entity->setPhoneNumberGroup($group); //$entity->setValueObject($group); $GLOBALS['log']->warning('group => ' .json_encode( $phoneNumberData )); $entity->setPhoneNumberGroup($phoneNumberData); $em->saveEntity($entity, $options);
Last edited by item; 11-06-2021, 12:03 AM.Tags: None
Leave a comment: