Forums › Forums › OroCRM › OroCRM – How do I? Questions › Add owner to guest in calendar event
This topic contains 3 replies, has 2 voices, and was last updated by zhex900 6 years, 6 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- July 27, 2017 at 3:56 am #29333
Hi,
I want to automatically add calendar owner to the event guest list. How do I implement this? For example, when the create event screen opened, I want to owner to be already added to the guest list.
Any example will be very helpful.
Thank you!
Jake He
- CreatorTopic
- AuthorReplies
- July 28, 2017 at 2:01 am #29334
Hello Jake He,
try the following solution:
1. Add an extension to CalendarEventAttendeesSelectType FormType for adding the owner to an Attendees (the “Guests” field). Extension code works only for create action and sets all the options needed for multiselect field to work and show correct data:
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980<?phpnamespace SomeBundle\Form\Extension;use Oro\Bundle\CalendarBundle\Entity\CalendarEvent;use Oro\Bundle\UserBundle\Entity\User;use Symfony\Component\Form\AbstractTypeExtension;use Symfony\Component\Form\FormInterface;use Symfony\Component\Form\FormView;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;class AddOwnerToAttendeesExtension extends AbstractTypeExtension{/*** @var TokenStorageInterface*/private $tokenStorage;/*** @param TokenStorageInterface $tokenStorage*/public function __construct(TokenStorageInterface $tokenStorage){$this->tokenStorage = $tokenStorage;}/*** {@inheritDoc}*/public function getExtendedType(){return 'oro_calendar_event_attendees_select';}/*** {@inheritDoc}*/public function buildView(FormView $view, FormInterface $form, array $options){if (!$form->getParent()) {return;}$calendarEvent = $form->getParent()->getData();if (!$calendarEvent instanceof CalendarEvent) {return;}if ($calendarEvent->getId() !== null) {return;}/** @var User $owner */$owner = $this->tokenStorage->getToken()->getUser();$this->addOwnerToAttendees($view, $owner);}/*** @param FormView $view* @param User $owner*/private function addOwnerToAttendees(FormView $view, User $owner){$view->vars['value'] = json_encode(['entityClass' => User::class,'entityId' => $owner->getId(),]);$view->vars['attr']['data-selected-data'] = json_encode(['text' => $owner->getFullName(),'displayName' => $owner->getFullName(),'email' => $owner->getEmail(),'type' => null,'status' => null,'userId' => $owner->getId(),'id' => $view->vars['value'],]);}}2. Add an extension service definition:
YAML123456somebundle.form_extension.set_owner_to_guests:class: 'SomeBundle\Form\Extension\AddOwnerToAttendeesExtension'arguments:- '@security.token_storage'tags:- { name: form.type_extension, alias: oro_calendar_event_attendees_select }Please, let us know if it worked for you.
July 30, 2017 at 9:01 pm #29335Works fine. Thank you!
September 6, 2017 at 4:53 am #29336Hi,
How do I implement the same function in CalendarEventAttendeesApiType? - AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.