Skip to content

Commit

Permalink
Update sulu from alexander-schranz/sulu-form-bundle from commit `c1…
Browse files Browse the repository at this point in the history
…10e72e44a58a0f53428c153e405124695506f6`

 - BUGFIX      #24    Fixed form preview request analyzer
 - BUGFIX      #24    Fixed second date field type
 - BUGFIX      #24    Fixed missing translation and documentation
 - ENHANCEMENT #24    Added missing documentation
 - BUGFIX      #24    Fixed success email not sent to email in data json
 - BUGFIX      #24    Fixed missing uniqueness in form fields table
 - BUGFIX      #24    Fixed permission denied on fields action
 - FEATURE     #24    Added toggler to set email as replyTo
 - BUGFIX      #24    Fixed exception controller redirect
 - BUGFIX      #24    Fixed form select by using native select
 - FEATURE     #24    Added media collection strategy tree
 - FEATURE     #24    Added support to add dynamic list to article bundle
 - BUGFIX      #24    Fixed csv export for bool values
 - ENHANCEMENT #24    Fixed sort on dynamic list and removed search
 - FEATURE     #24    Added dynamic form list and export
  • Loading branch information
alexander-schranz authored Feb 3, 2017
2 parents 1f5c34e + e89fad9 commit f150dc0
Show file tree
Hide file tree
Showing 47 changed files with 2,160 additions and 260 deletions.
58 changes: 58 additions & 0 deletions Admin/DynamicListNavigationProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Sulu\Bundle\FormBundle\Admin;

use Sulu\Bundle\AdminBundle\Navigation\ContentNavigationItem;
use Sulu\Bundle\AdminBundle\Navigation\ContentNavigationProviderInterface;
use Sulu\Bundle\AdminBundle\Navigation\DisplayCondition;

/**
* Register new tab for dynamic list to specific template.
*/
class DynamicListNavigationProvider implements ContentNavigationProviderInterface
{
/**
* @var string
*/
private $config;

/**
* DynamicListNavigationProvider constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
}

/**
* {@inheritdoc}
*/
public function getNavigationItems(array $options = [])
{
$items = [];

foreach ($this->config as $templateKey => $config) {
$item = new ContentNavigationItem('Formular');
$item->setAction('form-list');
$item->setDisplay(['edit']);
$item->setComponent('dynamics/list@suluform');
$item->setComponentOptions([
'template' => $templateKey,
'property' => $config['property'],
'view' => isset($config['view']) ? $config['view'] : 'default',
]);

$item->setDisplayConditions(
[
new DisplayCondition('template', DisplayCondition::OPERATOR_EQUAL, $templateKey),
]
);

$items[] = $item;
}

return $items;
}
}
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog

## dev-develop

- ENHANCEMENT #24 Update sulu from `alexander-schranz/sulu-form-bundle` from commit `c110e72e44a58a0f53428c153e405124695506f6`
- BUGFIX #24 Fixed form preview request analyzer
- BUGFIX #24 Fixed second date field type
- BUGFIX #24 Fixed missing translation and documentation
- ENHANCEMENT #24 Added missing documentation
- BUGFIX #24 Fixed success email not sent to email in data json
- BUGFIX #24 Fixed missing uniqueness in form fields table
- BUGFIX #24 Fixed permission denied on fields action
- FEATURE #24 Added toggler to set email as replyTo
- BUGFIX #24 Fixed exception controller redirect
- BUGFIX #24 Fixed form select by using native select
- FEATURE #24 Added media collection strategy tree
- FEATURE #24 Added support to add dynamic list to article bundle
- BUGFIX #24 Fixed csv export for bool values
- ENHANCEMENT #24 Fixed sort on dynamic list and removed search
- FEATURE #24 Added dynamic form list and export
- FEATURE #20 Added additional receivers for sending notification as CC or BCC
- ENHANCEMENT #23 Fixed composer json links and description
- BUGFIX #16 Fixed setting of entity value in dynamic which represents an array
Expand All @@ -15,4 +32,3 @@
- FEATURE #2 Changed title field for labels to texteditor
- ENHANCEMENT #- Updated namespaces and rename table names
- ENHANCEMENT #- Forked from `alexander-schranz/sulu-form-bundle` from commit `36a7cd11562ed0c9f64752b37707cc2771e0baca`

135 changes: 20 additions & 115 deletions Content/Types/FormSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

namespace Sulu\Bundle\FormBundle\Content\Types;

use Doctrine\ORM\NoResultException;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypePool;
use Sulu\Bundle\FormBundle\Entity\Dynamic;
use Sulu\Bundle\FormBundle\Event\DynFormSavedEvent;
use Sulu\Bundle\FormBundle\Form\HandlerInterface;
use Sulu\Bundle\FormBundle\Form\Type\DynamicFormType;
use Sulu\Bundle\FormBundle\Form\BuilderInterface;
use 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\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Form\FormInterface;

/**
* ContentType for selecting a form.
Expand All @@ -33,66 +24,26 @@ class FormSelect extends SimpleContentType
private $formRepository;

/**
* @var RequestStack
* @var BuilderInterface
*/
private $requestStack;

/**
* @var FormFactoryInterface
*/
private $formFactory;

/**
* @var HandlerInterface
*/
private $formHandler;

/**
* @var SystemCollectionManagerInterface
*/
private $systemCollectionManager;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

/**
* @var FormFieldTypePool
*/
private $typePool;
private $formBuilder;

/**
* FormSelect constructor.
*
* @param string $template
* @param FormRepository $formRepository
* @param RequestStack $requestStack
* @param FormFactoryInterface $formFactory
* @param HandlerInterface $formHandler
* @param SystemCollectionManagerInterface $systemCollectionManager
* @param EventDispatcherInterface $eventDispatcher
* @param FormFieldTypePool $typePool
* @param BuilderInterface $formBuilder
*/
public function __construct(
$template,
FormRepository $formRepository,
RequestStack $requestStack,
FormFactoryInterface $formFactory,
HandlerInterface $formHandler,
SystemCollectionManagerInterface $systemCollectionManager,
EventDispatcherInterface $eventDispatcher,
FormFieldTypePool $typePool
BuilderInterface $formBuilder
) {
parent::__construct('FormSelect', '');
$this->template = $template;
$this->formRepository = $formRepository;
$this->requestStack = $requestStack;
$this->formFactory = $formFactory;
$this->formHandler = $formHandler;
$this->systemCollectionManager = $systemCollectionManager;
$this->eventDispatcher = $eventDispatcher;
$this->typePool = $typePool;
$this->formBuilder = $formBuilder;
}

/**
Expand All @@ -106,67 +57,21 @@ public function getContentData(PropertyInterface $property)
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) {
$defaults[$field->getKey()] = $this->typePool->get($field->getType())->getDefaultValue($field, $locale);
}

// Create Form Type
$formType = new DynamicFormType(
$formEntity,
$locale,
$property->getName(),
$property->getStructure()->getView(),
$this->systemCollectionManager->getSystemCollection('sulu_form.attachments'),
$this->typePool
);

$form = $this->formFactory->create(
$formType,
new Dynamic($uuid, $locale, $formEntity, $webspaceKey, $defaults)
);

// handle request
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$dynamic = $form->getData();
$serializedObject = $formEntity->serializeForLocale($locale, $dynamic);

// save
$this->formHandler->handle(
$form,
[
'_form_type' => $formType,
'formEntity' => $serializedObject,
]
);

$event = new DynFormSavedEvent($serializedObject, $dynamic);
$this->eventDispatcher->dispatch(DynFormSavedEvent::NAME, $event);

// Do redirect after success
throw new HttpException(302, null, null, ['Location' => '?send=true']);
}

return $form->createView();
} catch (NoResultException $e) {
// do nothing
/** @var FormInterface $form */
list($formType, $form) = $this->formBuilder->build(
$id,
'page',
$property->getStructure()->getUuid(),
$property->getStructure()->getProperty('title')->getValue(),
$property->getStructure()->getLanguageCode(),
$property->getName()
);

if (!$form) {
return;
}

return;
return $form->createView();
}

/**
Expand Down
121 changes: 121 additions & 0 deletions Controller/DynamicController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace Sulu\Bundle\FormBundle\Controller;

use FOS\RestBundle\Routing\ClassResourceInterface;
use Sulu\Bundle\FormBundle\Entity\Form;
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
use Sulu\Component\Rest\RestController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

/**
* Controller to create dynamic form entries list.
*/
class DynamicController extends RestController implements ClassResourceInterface
{
/**
* Return dynamic form entries.
*
* @param Request $request
*
* @return Response
*/
public function cgetAction(Request $request)
{
$repository = $this->get('sulu_form.repository.dynamic');

$filters = $this->getFilters($request);
$page = $request->get('page', 1);
$limit = $request->get('limit');
$offset = (($page - 1) * $limit);
$view = $request->get('view', 'default');
$sortOrder = $request->get('sortOrder', 'asc');
$sortBy = $request->get('sortBy', 'created');

$entries = $repository->findBy(
$filters,
[$sortBy => $sortOrder],
$limit,
$offset
);

$entries = $this->get('sulu_form.list_builder.dynamic_list_factory')->build($entries, $view);

// avoid total request when entries < limit
if (count($entries) == $limit) {
$total = count($repository->findBy($filters));
} else {
// calculate total
$total = count($entries) + $offset;
}

// create list representation
$representation = new ListRepresentation(
$entries,
'dynamics',
$request->get('_route'),
$request->query->all(),
$page,
$limit,
$total
);

return $this->handleView($this->view($representation));
}

/**
* Returns the fields for a dynamic form.
*
* @param Request $request
*
* @return Response
*/
public function cgetFieldsAction(Request $request)
{
$form = $this->loadForm($request);
$locale = $request->getLocale();

$fieldDescriptors = $this->get('sulu_form.list_builder.dynamic_list_factory')
->getFieldDescriptors($form, $locale);

return $this->handleView($this->view(array_values($fieldDescriptors)));
}

/**
* Get filters.
*
* @param Request $request
*
* @return array
*/
protected function getFilters(Request $request)
{
$filters = [
'uuid' => $request->get('uuid'),
'webspaceKey' => $request->get('webspaceKey'),
'form' => $request->get('form'),
];

return array_filter($filters);
}

/**
* Get form.
*
* @param Request $request
*
* @return Form
*/
protected function loadForm(Request $request)
{
$formId = (int) $request->get('form');

if (!$formId) {
throw new BadRequestHttpException('"form" is required parameter');
}

return $this->get('sulu_form.repository.form')->findById($formId);
}
}
1 change: 1 addition & 0 deletions Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ private function getApiEntity(Form $entity, $locale)
'deactivateNotifyMails' => $translation->getDeactivateNotifyMails(),
'deactivateCustomerMails' => $translation->getDeactivateCustomerMails(),
'receivers' => $translation->getReceivers(),
'replyTo' => $translation->getReplyTo(),
];
}

Expand Down
Loading

0 comments on commit f150dc0

Please sign in to comment.