Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sulu/SuluFormBundle into develop
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
	UPGRADE.md
  • Loading branch information
alexander-schranz committed Sep 18, 2017
2 parents a2f9536 + f7ac097 commit 35240a7
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 97 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- FEATURE #83 Refractor static and dynamic form handling for symfony 3 compatibility
- FEATURE #91 Added Dutch translations

## 0.2.3

- HOTFIX #96 Fixed permission problem for template file

## 0.2.2

- BUGFIX #90 Fixed form data tab pagination
Expand Down
95 changes: 0 additions & 95 deletions Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Entity\Form;
use Sulu\Bundle\FormBundle\Mail\HelperInterface;
use Sulu\Bundle\FormBundle\Manager\FormManager;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactory;
use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineCaseFieldDescriptor;
Expand All @@ -27,7 +25,6 @@
use Sulu\Component\Security\SecuredControllerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\Translator;

/**
* Generated by https://github.com/alexander-schranz/sulu-backend-bundle.
Expand Down Expand Up @@ -155,98 +152,6 @@ public function getBundleName()
return 'SuluFormBundle';
}

/**
* @param Request $request
*
* @return Response
*/
public function cgetTemplateAction(Request $request)
{
$widths = [
[
'id' => 'full',
'name' => 'sulu_form.width.full',
],
[
'id' => 'half',
'name' => 'sulu_form.width.half',
],
[
'id' => 'one-third',
'name' => 'sulu_form.width.one-third',
],
[
'id' => 'two-thirds',
'name' => 'sulu_form.width.two-thirds',
],
[
'id' => 'one-quarter',
'name' => 'sulu_form.width.one-quarter',
],
[
'id' => 'three-quarters',
'name' => 'sulu_form.width.three-quarters',
],
[
'id' => 'one-sixth',
'name' => 'sulu_form.width.one-sixth',
],
[
'id' => 'five-sixths',
'name' => 'sulu_form.width.five-sixths',
],
];

$types = $this->get('sulu_form.dynamic.form_field_type_pool')->all();
$receiverTypes = [
'to' => HelperInterface::MAIL_RECEIVER_TO,
'cc' => HelperInterface::MAIL_RECEIVER_CC,
'bcc' => HelperInterface::MAIL_RECEIVER_BCC,
];

return $this->render(
$this->getBundleName() . ':' . $this->getListName() . ':template.html.twig',
[
'types' => $this->getSortedTypes($types),
'widths' => $widths,
'receiverTypes' => $receiverTypes,
'fallbackEmails' => [
'from' => $this->getParameter('sulu_form.mail.from'),
'to' => $this->getParameter('sulu_form.mail.to'),
],
]
);
}

/**
* @param FormFieldTypeInterface[] $types
*
* @return FormFieldTypeInterface[]
*/
public function getSortedTypes($types = [])
{
/** @var Translator $translator */
$translator = $this->get('translator');
$locale = $this->getUser()->getLocale();

$sortedTypes = [];
$returnTypes = [];

$i = 0;
foreach ($types as $alias => $type) {
$translation = $translator->trans($type->getConfiguration()->getTitle(), [], 'backend', $locale);
$sortedTypes[$translation . $i] = ['alias' => $alias, 'type' => $type];
++$i;
}

ksort($sortedTypes);
foreach ($sortedTypes as $sortedType) {
$returnTypes[$sortedType['alias']] = $sortedType['type'];
}

return $returnTypes;
}

/**
* @param Request $request
*
Expand Down
117 changes: 117 additions & 0 deletions Controller/TemplateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\FormBundle\Controller;

use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Mail\HelperInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\Translator;

/**
* Generated by https://github.com/alexander-schranz/sulu-backend-bundle.
*/
class TemplateController extends Controller
{
/**
* @param Request $request
*
* @return Response
*/
public function formAction(Request $request)
{
$widths = [
[
'id' => 'full',
'name' => 'sulu_form.width.full',
],
[
'id' => 'half',
'name' => 'sulu_form.width.half',
],
[
'id' => 'one-third',
'name' => 'sulu_form.width.one-third',
],
[
'id' => 'two-thirds',
'name' => 'sulu_form.width.two-thirds',
],
[
'id' => 'one-quarter',
'name' => 'sulu_form.width.one-quarter',
],
[
'id' => 'three-quarters',
'name' => 'sulu_form.width.three-quarters',
],
[
'id' => 'one-sixth',
'name' => 'sulu_form.width.one-sixth',
],
[
'id' => 'five-sixths',
'name' => 'sulu_form.width.five-sixths',
],
];

$types = $this->get('sulu_form.dynamic.form_field_type_pool')->all();
$receiverTypes = [
'to' => HelperInterface::MAIL_RECEIVER_TO,
'cc' => HelperInterface::MAIL_RECEIVER_CC,
'bcc' => HelperInterface::MAIL_RECEIVER_BCC,
];

return $this->render(
'SuluFormBundle:forms:template.html.twig',
[
'types' => $this->getSortedTypes($types),
'widths' => $widths,
'receiverTypes' => $receiverTypes,
'fallbackEmails' => [
'from' => $this->getParameter('sulu_form.mail.from'),
'to' => $this->getParameter('sulu_form.mail.to'),
],
]
);
}

/**
* @param FormFieldTypeInterface[] $types
*
* @return FormFieldTypeInterface[]
*/
public function getSortedTypes($types = [])
{
/** @var Translator $translator */
$translator = $this->get('translator');
$locale = $this->getUser()->getLocale();

$sortedTypes = [];
$returnTypes = [];

$i = 0;
foreach ($types as $alias => $type) {
$translation = $translator->trans($type->getConfiguration()->getTitle(), [], 'backend', $locale);
$sortedTypes[$translation . $i] = ['alias' => $alias, 'type' => $type];
++$i;
}

ksort($sortedTypes);
foreach ($sortedTypes as $sortedType) {
$returnTypes[$sortedType['alias']] = $sortedType['type'];
}

return $returnTypes;
}
}
5 changes: 5 additions & 0 deletions Resources/config/routing_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ sulu_form.csv_overlay:
defaults:
_controller: FrameworkBundle:Template:template
template: SuluFormBundle:CsvExport:form.html.twig

sulu_form.forms.template:
path: /form/templates/form.html
defaults:
_controller: SuluFormBundle:Template:form
2 changes: 1 addition & 1 deletion Resources/public/dist/components/forms/form/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/public/js/components/forms/form/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define(function () {
var tabs = {
'general': {
'name': 'general',
'url': '/admin/api/forms/template',
'url': '/admin/api/form/templates/form.html',
'formSelector': '#form-form'
}
};
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ sulu_form:
- `Sulu\Bundle\FormBundle\Form\Builder::build` return a FormInterface instead of an array
- `Sulu\Bundle\FormBundle\Event\MailSubscriber` was removed

## 0.2.3

### Form Template file moved

`FormController:cgetTemplateAction` (/admin/api/forms/template) was moved to `TemplateController:formAction` (/admin/api//form/templates/form.html).

## 0.2.0

### Upgrade database schema
Expand Down

0 comments on commit 35240a7

Please sign in to comment.