public function processUpdatePolicy(FormActionEvent $event)
 {
     // Don't update anything if we just want to cancel the draft.
     if ($event->getClickedButton() === 'removeDraft') {
         return;
     }
     /** @var \EzSystems\RepositoryForms\Data\Role\PolicyCreateData|\EzSystems\RepositoryForms\Data\Role\PolicyUpdateData $data */
     $data = $event->getData();
     if ($data->isNew() && $data->moduleFunction) {
         list($module, $function) = explode('|', $data->moduleFunction);
         $data->module = $module;
         $data->function = $function;
         $initialRoleDraft = $data->roleDraft;
         $updatedRoleDraft = $this->roleService->addPolicyByRoleDraft($initialRoleDraft, $data);
         $initialPoliciesById = $this->getPoliciesById($initialRoleDraft);
         $updatedPoliciesById = $this->getPoliciesById($updatedRoleDraft);
         foreach ($updatedPoliciesById as $policyId => $policyDraft) {
             if (!isset($initialPoliciesById[$policyId])) {
                 $data->setPolicyDraft($policyDraft);
                 break;
             }
         }
     } else {
         // Only save limitations on update.
         // It is not possible by design to update policy module/function.
         foreach ($data->limitationsData as $limitation) {
             // Add posted limitations as valid ones, recognized by RoleService.
             if (!empty($limitation->limitationValues)) {
                 $data->addLimitation($limitation);
             }
         }
         $this->roleService->updatePolicyByRoleDraft($data->roleDraft, $data->policyDraft, $data);
     }
 }
 public function processDefaultAction(FormActionEvent $event)
 {
     if ($event->getClickedButton() === 'removeDraft') {
         return;
     }
     $this->notify('content_type.notification.draft_updated', [], 'content_type');
 }
 public function processDefaultAction(FormActionEvent $event)
 {
     // Don't update anything if we just want to cancel the draft.
     if ($event->getClickedButton() === 'removeDraft') {
         return;
     }
     /** @var \EzSystems\RepositoryForms\Data\Role\RoleData $roleData */
     $roleData = $event->getData();
     $roleDraft = $roleData->roleDraft;
     $this->roleService->updateRoleDraft($roleDraft, $roleData);
 }
 public function testConstruct()
 {
     $form = $this->getMock('\\Symfony\\Component\\Form\\FormInterface');
     $data = new stdClass();
     $clickedButton = 'fooButton';
     $options = ['languageCode' => 'eng-GB', 'foo' => 'bar'];
     $event = new FormActionEvent($form, $data, $clickedButton, $options);
     self::assertSame($form, $event->getForm());
     self::assertSame($data, $event->getData());
     self::assertSame($clickedButton, $event->getClickedButton());
     self::assertSame($options, $event->getOptions());
 }
 public function processDefaultAction(FormActionEvent $event)
 {
     // Don't update anything if we just want to cancel the draft.
     if ($event->getClickedButton() === 'removeDraft') {
         return;
     }
     // Always update FieldDefinitions and ContentTypeDraft
     /** @var \EzSystems\RepositoryForms\Data\ContentTypeData $contentTypeData */
     $contentTypeData = $event->getData();
     $contentTypeDraft = $contentTypeData->contentTypeDraft;
     foreach ($contentTypeData->fieldDefinitionsData as $fieldDefData) {
         $this->contentTypeService->updateFieldDefinition($contentTypeDraft, $fieldDefData->fieldDefinition, $fieldDefData);
     }
     $this->contentTypeService->updateContentTypeDraft($contentTypeDraft, $contentTypeData);
 }
 /**
  * Returns true if the event is the default event, meaning Enter has been pressed in the form.
  *
  * There's no need to process the default action (save) for explicit events (save, cancel).
  * Saving is not needed when cancelling, and when the Save button is clicked the save action takes care of it.
  * The default action is only needed when the form has been submitted by pressing Enter.
  *
  * @param FormActionEvent $event
  *
  * @return bool
  */
 protected function isDefaultEvent(FormActionEvent $event)
 {
     return $event->getClickedButton() === null;
 }
 /**
  * Save the role if no button was clicked (i.e. enter was pressed in the form).
  *
  * The role should not be saved if cancel was pressed, and if save was pressed this is done in the save action.
  *
  * @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
  */
 public function processDefaultAction(FormActionEvent $event)
 {
     if ($event->getClickedButton() === null) {
         $this->processSaveRole($event);
     }
 }