I'm trying to create a hook to add the primary phone number to the meeting entity. What I'd like to do is pull the phone number for the account and populate a varchar phone field to display on the detail view.
The issue seems to be with accessing the entity_phone_number table. Is that table mapped differently than the others? Is there a better way to accomplish this?
Here is the hook that I've created:
public function beforeSave(Entity $meeting)
{
//I have removed other parent options and only have accounts as parent type for meetings
$accountID = $meeting->get('accountId');
$phoneList = $this->getEntityManager()->getRepository('EntityPhoneNumber')->where(array(
'entityId' => $accountID,
'primary' => '1'
))->findOne();
$phoneNumberID = $phoneList->get('phoneNumberId');
$phoneNumber = $this->getEntityManager()->getEntity('PhoneNumber', $phoneNumberID);
$phone = $phoneNumber->get('name');
//I have created a varchar field named phone to accept the phone number.
$meeting->set('phone', $phone);
}
The issue seems to be with accessing the entity_phone_number table. Is that table mapped differently than the others? Is there a better way to accomplish this?
Here is the hook that I've created:
public function beforeSave(Entity $meeting)
{
//I have removed other parent options and only have accounts as parent type for meetings
$accountID = $meeting->get('accountId');
$phoneList = $this->getEntityManager()->getRepository('EntityPhoneNumber')->where(array(
'entityId' => $accountID,
'primary' => '1'
))->findOne();
$phoneNumberID = $phoneList->get('phoneNumberId');
$phoneNumber = $this->getEntityManager()->getEntity('PhoneNumber', $phoneNumberID);
$phone = $phoneNumber->get('name');
//I have created a varchar field named phone to accept the phone number.
$meeting->set('phone', $phone);
}
Comment