Skip to content

Commit

Permalink
deprecate static forms and update documentation (sulu#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored and wachterjohannes committed Jun 27, 2017
1 parent 96d8fa6 commit 4a92810
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 40 deletions.
6 changes: 0 additions & 6 deletions Admin/DynamicListNavigationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ class DynamicListNavigationProvider implements ContentNavigationProviderInterfac
*/
private $config;

/**
* @var string
*/
private $type;

/**
* DynamicListNavigationProvider constructor.
*
* @param array $config
* @param array $type
*/
public function __construct(array $config)
{
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## dev-develop

- ENHANCEMENT #73 Deprecate static forms and update documentation
- BUGFIX #72 Fixed add and remove a field of same type at same time
- FEATURE #63 Added possibility to use form content type in other modules
- ENHANCEMENT #60 Added `sulu_admin.email` as default mail address and show them as placeholder in form template
Expand Down
2 changes: 1 addition & 1 deletion Dynamic/Types/MultiChoiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getChoiceOptions(FormFieldTranslation $translation, $expanded =
}

/**
* Returns default options for multichoise form type.
* Returns default options for multichoice form type.
*
* @param string $value
*
Expand Down
4 changes: 3 additions & 1 deletion Entity/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ class Dynamic implements TimestampableInterface
private $changed;

/**
* @param string $type
* @param string $typeId
* @param string $locale
* @param Form $formId
* @param null|string $webspaceKey
* @param array $data
*/
public function __construct($typeId, $locale, $formId, $webspaceKey = null, $data = [])
public function __construct($type, $typeId, $locale, $formId, $webspaceKey = null, $data = [])
{
$this->type = $type;
$this->typeId = $typeId;
$this->locale = $locale;
$this->form = $formId;
Expand Down
19 changes: 10 additions & 9 deletions Form/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ protected function buildForm($id, $type, $typeId, $locale, $name)
// Create Form
$form = $this->createForm(
$formType,
$type,
$typeId,
$locale,
$formEntity,
Expand Down Expand Up @@ -250,20 +251,21 @@ protected function getKey($id, $type, $typeId, $locale, $name)
/**
* Create form.
*
* @param $formType
* @param $typeId
* @param $locale
* @param $formEntity
* @param $webspaceKey
* @param $defaults
* @param string $formType
* @param string $type
* @param string $typeId
* @param string $locale
* @param Form $formEntity
* @param string $webspaceKey
* @param array $defaults
*
* @return FormInterface
*/
protected function createForm($formType, $typeId, $locale, $formEntity, $webspaceKey, $defaults)
protected function createForm($formType, $type, $typeId, $locale, $formEntity, $webspaceKey, $defaults)
{
return $this->formFactory->create(
$formType,
new Dynamic($typeId, $locale, $formEntity, $webspaceKey, $defaults)
new Dynamic($type, $typeId, $locale, $formEntity, $webspaceKey, $defaults)
);
}

Expand Down Expand Up @@ -302,7 +304,6 @@ protected function loadFormEntity($id, $locale)
* @param string $name
* @param string $type
* @param string $typeId
* @param string $typeName
*
* @return DynamicFormType
*/
Expand Down
3 changes: 3 additions & 0 deletions Form/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\Form\AbstractType as SymfonyAbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @deprecated static forms are not longer supported this way
*/
abstract class AbstractType extends SymfonyAbstractType implements TypeInterface
{
/**
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/doctrine/Dynamic.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<generator strategy="AUTO"/>
</id>

<field name="type" column="type" type="string" nullable="false"/>
<field name="typeId" column="typeId" type="string" nullable="false"/>
<field name="locale" column="locale" type="string" nullable="false"/>
<field name="webspaceKey" column="webspaceKey" type="string" nullable="false"/>
<field name="type" column="type" type="string" nullable="false"/>

<field name="salutation" column="salutation" type="string" nullable="true"/>
<field name="title" column="title" type="string" nullable="true"/>
Expand Down
74 changes: 56 additions & 18 deletions Resources/doc/dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,63 @@ Create a template in `app/Resources/pages` which uses the content type of the bu
one of the dynamic templates which can be created in the Sulu backend.

```xml
<property name="form" type="form_select">
<?xml version="1.0" ?>
<template xmlns="http://schemas.sulu.io/template/template"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/template-1.0.xsd">

<key>form</key>

<view>AppBundle:website:templates/pages/default</view>
<controller>SuluWebsiteBundle:Default:index</controller>
<cacheLifetime>1209600</cacheLifetime>

<meta>
<title lang="de">Formular</title>
<title lang="en">Form</title>
<title lang="de">Formular</title>
</meta>

<params>
<param name="type" value="page" />
</params>
</property>
<properties>
<section name="highlight">
<properties>
<property name="title" type="text_line" mandatory="true">
<meta>
<title lang="en">Title</title>
<title lang="de">Titel</title>
</meta>
<params>
<param name="headline" value="true"/>
</params>

<tag name="sulu.rlp.part"/>
</property>

<property name="url" type="resource_locator" mandatory="true">
<meta>
<title lang="en">Resourcelocator</title>
<title lang="de">Adresse</title>
</meta>

<tag name="sulu.rlp"/>
</property>
</properties>
</section>

<property name="form" type="form_select">
<meta>
<title lang="de">Formular</title>
<title lang="en">Form</title>
</meta>

<params>
<param name="type" value="page" />
</params>
</property>
</properties>
</template>
```

## Controller

For the dynamic form type you can use the default sulu controller in your template or a custom one.

```xml
<controller>SuluWebsiteBundle:Default:index</controller>
```
Use `article` as `type` when you use the form_select inside article template.

## Output Form and customize

Expand Down Expand Up @@ -79,11 +117,11 @@ To visualise a tab in the Sulu template, simply configured the following in your
```yml
sulu_form:
dynamic_lists:
<tab_navigation>: # For sulu pages "content".
<unique_key>: # Mostly the same as the template key.
template: <template_key>
property: <form_select_property_name>
type: <form_type> # (e.g. page, article, event,…)
content: # tab navigation key e.g. "content" for sulu pages or "article" for sulu articles.
form: # unique key mostly the same as the template key or a combination between template and property key.
template: form # template key
property: form # form property name
type: page # the site type e.g. page, article, … (same as the content type type param)
```

**Now a tab should be visible with a list you can export**
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Sulu Form Bundle

Simple handling from Symfony Forms in [Sulu.io](http://sulu.io).
You can use this Bundle to create and handle static *(integrated in a Sulu page or loaded via AJAX)* or dynamic forms.
You can use this Bundle to create and handle dynamic forms.

## Features

Expand Down Expand Up @@ -74,8 +74,8 @@ Make sure you've set the correct permissions in the Sulu backend for this bundle
## Usage
- [Static Forms](static.md "Static Forms")
- [Dynamic Forms](dynamic.md "Dynamic Forms")
- [Static Forms](static.md "Static Forms")(deprecated)
## Additional form fields
Expand Down
6 changes: 5 additions & 1 deletion Resources/doc/static.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Static Form

The following is showing an example how you can use the bundle to create a static form.
_The current way to create static form is deprecated_
_its recommend to create your own custom controller_
_instead of using the form bundle for it_

The following is showing an example how you can use the bundle to create a static form (deprecated).

## Basic Sulu Template

Expand Down
2 changes: 1 addition & 1 deletion Twig/FormTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class FormTwigExtension extends \Twig_Extension
{
/**
* @var FormRepository
* @var BuilderInterface
*/
private $formBuilder;

Expand Down
31 changes: 31 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## dev-develop

### Set type for content type definition

With the compatibility to use the form bundle in articles it is needed to define
the type in the xml definition.

__before__

```xml
<property name="form" type="form_select">
<meta>
<title lang="de">Formular</title>
<title lang="en">Form</title>
</meta>
</property>
```

__after__

```xml
<property name="form" type="form_select">
<meta>
<title lang="de">Formular</title>
<title lang="en">Form</title>
</meta>

<params>
<param name="type" value="page" />
</params>
</property>
```

### Upgrade database schema

```sql
Expand Down

0 comments on commit 4a92810

Please sign in to comment.