public function testGetOption()
 {
     $objectOption = new stdClass();
     $options = ['languageCode' => 'eng-GB', 'foo' => 'bar', 'obj' => $objectOption];
     $event = new FormActionEvent($this->getMock('\\Symfony\\Component\\Form\\FormInterface'), new stdClass(), 'fooButton', $options);
     self::assertTrue($event->hasOption('languageCode'));
     self::assertTrue($event->hasOption('foo'));
     self::assertTrue($event->hasOption('obj'));
     self::assertSame('eng-GB', $event->getOption('languageCode'));
     self::assertSame('bar', $event->getOption('foo'));
     self::assertSame($objectOption, $event->getOption('obj'));
 }
 public function processAddFieldDefinition(FormActionEvent $event)
 {
     $contentTypeDraft = $event->getData()->contentTypeDraft;
     $fieldTypeIdentifier = $event->getForm()->get('fieldTypeSelection')->getData();
     $fieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => sprintf('new_%s_%d', $fieldTypeIdentifier, count($contentTypeDraft->fieldDefinitions) + 1), 'names' => [$event->getOption('languageCode') => 'New FieldDefinition']]);
     $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreateStruct);
 }
 public function processAddFieldDefinition(FormActionEvent $event)
 {
     // Reload the draft, to make sure we include any changes made in the current form submit
     $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($event->getData()->contentTypeDraft->id);
     $fieldTypeIdentifier = $event->getForm()->get('fieldTypeSelection')->getData();
     $maxFieldPos = 0;
     foreach ($contentTypeDraft->fieldDefinitions as $existingFieldDef) {
         if ($existingFieldDef->position > $maxFieldPos) {
             $maxFieldPos = $existingFieldDef->position;
         }
     }
     $fieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => sprintf('new_%s_%d', $fieldTypeIdentifier, count($contentTypeDraft->fieldDefinitions) + 1), 'names' => [$event->getOption('languageCode') => 'New FieldDefinition'], 'position' => $maxFieldPos + 1]);
     $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreateStruct);
 }
 public function processRemoveContentTypeDraft(FormActionEvent $event)
 {
     /** @var ContentTypeDraft $contentTypeDraft */
     $contentTypeDraft = $event->getData()->contentTypeDraft;
     $languageCode = $event->getOption('languageCode');
     // Redirect response will be different if we're dealing with an existing ContentType or a newly created one, which has been discarded.
     try {
         // This will throw a NotFoundException if a published version doesn't exist for this ContentType.
         $this->contentTypeService->loadContentType($contentTypeDraft->id);
         $response = $this->generateRedirectResponse($contentTypeDraft, $languageCode);
     } catch (NotFoundException $e) {
         // ContentTypeDraft was newly created, but then discarded.
         // Redirect to the ContentTypeGroup view.
         $response = new FormProcessingDoneResponse($this->router->generate('admin_contenttypeGroupView', ['contentTypeGroupId' => $contentTypeDraft->contentTypeGroups[0]->id]));
     }
     $event->setResponse($response);
     $this->notify('content_type.notification.draft_removed', [], 'content_type');
 }