forked from sulu/SuluCommunityBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sulu#54 from alexander-schranz/develop
Release: 1.0.0-RC1
- Loading branch information
Showing
100 changed files
with
6,776 additions
and
900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace L91\Sulu\Bundle\FormBundle\Admin; | ||
|
||
use Sulu\Bundle\AdminBundle\Navigation\ContentNavigationItem; | ||
use Sulu\Bundle\AdminBundle\Navigation\ContentNavigationProviderInterface; | ||
|
||
/** | ||
* Generated by https://github.com/alexander-schranz/sulu-backend-bundle. | ||
*/ | ||
class FormNavigationProvider implements ContentNavigationProviderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getNavigationItems(array $options = []) | ||
{ | ||
$navigationItems = []; | ||
|
||
$navigationItems['detail'] = new ContentNavigationItem('l91.sulu.form.navigation.details'); | ||
$navigationItems['detail']->setAction('general'); | ||
$navigationItems['detail']->setComponent('forms@l91suluform'); | ||
$navigationItems['detail']->setComponentOptions([ | ||
'display' => 'form', | ||
'content' => 'general', | ||
]); | ||
|
||
return $navigationItems; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
<?php | ||
|
||
namespace L91\Sulu\Bundle\FormBundle\Content\Types; | ||
|
||
use Doctrine\ORM\NoResultException; | ||
use L91\Sulu\Bundle\FormBundle\Entity\Dynamic; | ||
use L91\Sulu\Bundle\FormBundle\Form\HandlerInterface; | ||
use L91\Sulu\Bundle\FormBundle\Form\Type\DynamicFormType; | ||
use L91\Sulu\Bundle\FormBundle\Repository\FormRepository; | ||
use Sulu\Component\Content\Compat\PropertyInterface; | ||
use Sulu\Component\Content\SimpleContentType; | ||
use Sulu\Component\Media\SystemCollections\SystemCollectionManagerInterface; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
/** | ||
* ContentType for selecting a form. | ||
*/ | ||
class FormSelect extends SimpleContentType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $template; | ||
|
||
/** | ||
* @var FormRepository | ||
*/ | ||
private $formRepository; | ||
|
||
/** | ||
* @var RequestStack | ||
*/ | ||
private $requestStack; | ||
|
||
/** | ||
* @var FormFactoryInterface | ||
*/ | ||
private $formFactory; | ||
|
||
/** | ||
* @var HandlerInterface | ||
*/ | ||
private $formHandler; | ||
|
||
/** | ||
* @var SystemCollectionManagerInterface | ||
*/ | ||
private $systemCollectionManager; | ||
|
||
/** | ||
* FormSelect constructor. | ||
* | ||
* @param string $template | ||
* @param FormRepository $formRepository | ||
* @param RequestStack $requestStack | ||
* @param FormFactoryInterface $formFactory | ||
* @param HandlerInterface $formHandler | ||
* @param SystemCollectionManagerInterface $systemCollectionManager | ||
*/ | ||
public function __construct( | ||
$template, | ||
FormRepository $formRepository, | ||
RequestStack $requestStack, | ||
FormFactoryInterface $formFactory, | ||
HandlerInterface $formHandler, | ||
SystemCollectionManagerInterface $systemCollectionManager | ||
) { | ||
parent::__construct('FormSelect', ''); | ||
$this->template = $template; | ||
$this->formRepository = $formRepository; | ||
$this->requestStack = $requestStack; | ||
$this->formFactory = $formFactory; | ||
$this->formHandler = $formHandler; | ||
$this->systemCollectionManager = $systemCollectionManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getContentData(PropertyInterface $property) | ||
{ | ||
$id = (int) $property->getValue(); | ||
|
||
if (!$id) { | ||
return; | ||
} | ||
|
||
$request = $this->requestStack->getCurrentRequest(); | ||
|
||
$form = null; | ||
|
||
try { | ||
// Create Dynamic Data | ||
$uuid = $property->getStructure()->getUuid(); | ||
$webspaceKey = $property->getStructure()->getWebspaceKey(); | ||
$locale = $property->getStructure()->getLanguageCode(); | ||
$formEntity = $this->formRepository->findById($id, $locale); | ||
|
||
// set Defaults | ||
$defaults = []; | ||
foreach ($formEntity->getFields() as $field) { | ||
$translation = $field->getTranslation($locale); | ||
|
||
if ($translation && $translation->getDefaultValue()) { | ||
$value = $translation->getDefaultValue(); | ||
|
||
// handle special types | ||
switch ($field->getType()) { | ||
case Dynamic::TYPE_DATE: | ||
$value = new \DateTime($value); | ||
break; | ||
case Dynamic::TYPE_DROPDOWN_MULTIPLE: | ||
case Dynamic::TYPE_CHECKBOX_MULTIPLE: | ||
$value = preg_split('/\r\n|\r|\n/', $value, -1, PREG_SPLIT_NO_EMPTY); | ||
break; | ||
} | ||
|
||
$defaults[$field->getKey()] = $value; | ||
} | ||
} | ||
|
||
// Create Form Type | ||
$formType = new DynamicFormType( | ||
$formEntity, | ||
$locale, | ||
$property->getName(), | ||
$property->getStructure()->getView(), | ||
$this->systemCollectionManager->getSystemCollection('l91_sulu_form.attachments') | ||
); | ||
|
||
$form = $this->formFactory->create( | ||
$formType, | ||
new Dynamic($uuid, $locale, $id, $webspaceKey, $defaults) | ||
); | ||
|
||
// handle request | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
// save | ||
$this->formHandler->handle( | ||
$form, | ||
[ | ||
'_form_type' => $formType, | ||
'formEntity' => $formEntity->serializeForLocale($locale, $form->getData()), | ||
] | ||
); | ||
|
||
// Do redirect after success | ||
throw new HttpException(302, null, null, ['Location' => '?send=true']); | ||
} | ||
|
||
return $form->createView(); | ||
} catch (NoResultException $e) { | ||
// do nothing | ||
} | ||
|
||
return; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getViewData(PropertyInterface $property) | ||
{ | ||
$id = (int) $property->getValue(); | ||
|
||
if (!$id) { | ||
return []; | ||
} | ||
|
||
$locale = $property->getStructure()->getLanguageCode(); | ||
|
||
$formEntity = $this->formRepository->findById($id, $locale); | ||
|
||
return [ | ||
'entity' => $formEntity->serializeForLocale($locale), | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTemplate() | ||
{ | ||
return $this->template; | ||
} | ||
} |
Oops, something went wrong.