I'm trying to write a User afterSave hook that will allow me to create a related entity that has a Document as an attachment
It first successfully grabs the document I would like to attach, and then I had hoped I could just do the following, which is partially borrowed from the Document controller/service code (bolded part):
$doc = $this->getEntityManager()->getRepository('Document')->order('createdAt', 'DESC')->findOne();
$attachment = $doc->getRecordService()->getAttachmentList($doc->id)->getValueMapList();
$tos = $this->getEntityManager()->getEntity('TermsOfService');
$tos->set(array(
'name' => 'Terms of Service',
'termsId' => $attachment->id,
'assignedUserId' => $entity->id
));
$this->getEntityManager()->saveEntity($tos);
But $doc ->getRecordService() fails because it's not found...is there some other way to get a reference to the Document getRecordService function, or any other recommended way to get the attachment ID so I can create this other TermsOfService entity with it?
Thanks.
It first successfully grabs the document I would like to attach, and then I had hoped I could just do the following, which is partially borrowed from the Document controller/service code (bolded part):
$doc = $this->getEntityManager()->getRepository('Document')->order('createdAt', 'DESC')->findOne();
$attachment = $doc->getRecordService()->getAttachmentList($doc->id)->getValueMapList();
$tos = $this->getEntityManager()->getEntity('TermsOfService');
$tos->set(array(
'name' => 'Terms of Service',
'termsId' => $attachment->id,
'assignedUserId' => $entity->id
));
$this->getEntityManager()->saveEntity($tos);
But $doc ->getRecordService() fails because it's not found...is there some other way to get a reference to the Document getRecordService function, or any other recommended way to get the attachment ID so I can create this other TermsOfService entity with it?
Thanks.
Comment