Skip to content

Commit

Permalink
Merge pull request sulu#49 from alexander-schranz/feature/dynamic-for…
Browse files Browse the repository at this point in the history
…m-corrections

WIP: Default Export + Select to Dropdown
  • Loading branch information
thomasduenser authored Jul 29, 2016
2 parents 56de39c + 3db7620 commit 43e6b5d
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Content/Types/FormSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getContentData(PropertyInterface $property)

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

// handle request
Expand Down
17 changes: 12 additions & 5 deletions Entity/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Dynamic implements TimestampableInterface
const TYPE_ATTACHMENT = 'attachment';
const TYPE_CHECKBOX = 'checkbox';
const TYPE_CHECKBOX_MULTIPLE = 'checkboxMultiple';
const TYPE_SELECT = 'select';
const TYPE_SELECT_MULTIPLE = 'selectMultiple';
const TYPE_DROPDOWN = 'dropdown';
const TYPE_DROPDOWN_MULTIPLE = 'dropdownMultiple';
const TYPE_RADIO_BUTTONS = 'radioButtons';

/**
Expand All @@ -49,6 +49,11 @@ class Dynamic implements TimestampableInterface
*/
private $locale;

/**
* @var int
*/
private $formId;

/**
* @var string
*/
Expand Down Expand Up @@ -157,12 +162,12 @@ class Dynamic implements TimestampableInterface
/**
* @var string
*/
private $select;
private $dropdown;

/**
* @var string
*/
private $selectMultiple;
private $dropdownMultiple;

/**
* @var string
Expand Down Expand Up @@ -199,13 +204,15 @@ public static function getConstants()
/**
* @param string $uuid
* @param string $locale
* @param int $formId
* @param null|string $webspaceKey
* @param array $data
*/
public function __construct($uuid, $locale, $webspaceKey = null, $data = [])
public function __construct($uuid, $locale, $formId, $webspaceKey = null, $data = [])
{
$this->uuid = $uuid;
$this->locale = $locale;
$this->formId = $formId;
$this->webspaceKey = $webspaceKey;

foreach ($data as $name => $value) {
Expand Down
4 changes: 2 additions & 2 deletions Form/Type/DynamicFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
case Dynamic::TYPE_CHECKBOX_MULTIPLE:
$type = $this->createChoiceType($translation, $options, true, true);
break;
case Dynamic::TYPE_SELECT:
case Dynamic::TYPE_DROPDOWN:
$type = $this->createChoiceType($translation, $options);
break;
case Dynamic::TYPE_SELECT_MULTIPLE:
case Dynamic::TYPE_DROPDOWN_MULTIPLE:
$type = $this->createChoiceType($translation, $options, false, true);
break;
case Dynamic::TYPE_RADIO_BUTTONS:
Expand Down
66 changes: 66 additions & 0 deletions Provider/DynamicProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace L91\Sulu\Bundle\FormBundle\Provider;

use L91\Sulu\Bundle\FormBundle\Entity\Dynamic;
use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineFieldDescriptor;

class DynamicProvider implements ListProviderInterface
{
/**
* {@inheritdoc}
*/
public function getFieldDescriptors($webspace, $locale, $uuid)
{
$fieldDescriptors = [
'id' => $this->createFieldDescriptor('id', '', 'public.id'),
'firstName' => $this->createFieldDescriptor('firstName'),
'lastName' => $this->createFieldDescriptor('lastName'),
'email' => $this->createFieldDescriptor('email'),
'phone' => $this->createFieldDescriptor('phone'),
'street' => $this->createFieldDescriptor('street'),
'zip' => $this->createFieldDescriptor('zip'),
'city' => $this->createFieldDescriptor('city'),
'state' => $this->createFieldDescriptor('state'),
'country' => $this->createFieldDescriptor('country'),
'function' => $this->createFieldDescriptor('function'),
'company' => $this->createFieldDescriptor('company'),
'created' => $this->createFieldDescriptor('created', 'date', 'public.created'),
];

return $fieldDescriptors;
}

/**
* @param string $name
* @param bool $disabled
* @param string $type
*
* @return DoctrineFieldDescriptor
*/
protected function createFieldDescriptor($name, $type = '', $translationKey = '', $disabled = false)
{
if (!$translationKey) {
$translationKey = 'l91_sulu_form.type.' . strtolower($name);
}

return new DoctrineFieldDescriptor(
$name,
$name,
Dynamic::class,
$translationKey,
[],
$disabled,
false,
$type
);
}

/**
* {@inheritdoc}
*/
public function getEntityName($webspace, $locale, $uuid)
{
return Dynamic::class;
}
}
5 changes: 3 additions & 2 deletions Resources/config/doctrine/Dynamic.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<field name="uuid" column="uuid" type="string" nullable="false"/>
<field name="locale" column="locale" type="string" nullable="false"/>
<field name="formId" column="formId" type="integer" nullable="false"/>
<field name="webspaceKey" column="webspaceKey" type="string" nullable="false"/>

<field name="salutation" column="salutation" type="string" nullable="true"/>
Expand All @@ -31,8 +32,8 @@
<field name="attachment" column="attachment" type="string" nullable="true"/>
<field name="checkbox" column="checkbox" type="string" nullable="true"/>
<field name="checkboxMultiple" column="checkboxMultiple" type="string" nullable="true"/>
<field name="select" column="select" type="string" nullable="true"/>
<field name="selectMultiple" column="selectMultiple" type="string" nullable="true"/>
<field name="dropdown" column="dropdown" type="string" nullable="true"/>
<field name="dropdownMultiple" column="dropdownMultiple" type="string" nullable="true"/>
<field name="radioButtons" column="radioButtons" type="string" nullable="true"/>

<field name="data" column="data" type="text" nullable="true"/>
Expand Down
4 changes: 2 additions & 2 deletions Resources/translations/sulu/backend.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
<target>Checkboxes</target>
</trans-unit>
<trans-unit id="32">
<source>l91_sulu_form.type.select</source>
<source>l91_sulu_form.type.dropdown</source>
<target>Dropdown</target>
</trans-unit>
<trans-unit id="33">
<source>l91_sulu_form.type.selectmultiple</source>
<source>l91_sulu_form.type.dropdownmultiple</source>
<target>Dropdown (Mehrfachauswahl)</target>
</trans-unit>
<trans-unit id="34">
Expand Down
4 changes: 2 additions & 2 deletions Resources/translations/sulu/backend.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
<target>Checkboxes</target>
</trans-unit>
<trans-unit id="32">
<source>l91_sulu_form.type.select</source>
<source>l91_sulu_form.type.dropdown</source>
<target>Select</target>
</trans-unit>
<trans-unit id="33">
<source>l91_sulu_form.type.selectmultiple</source>
<source>l91_sulu_form.type.dropdownmultiple</source>
<target>Select (multiple)</target>
</trans-unit>
<trans-unit id="34">
Expand Down
4 changes: 2 additions & 2 deletions Resources/translations/sulu/backend.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@
<target>Checkboxes</target>
</trans-unit>
<trans-unit id="32">
<source>l91_sulu_form.type.select</source>
<source>l91_sulu_form.type.dropdown</source>
<target>Select</target>
</trans-unit>
<trans-unit id="33">
<source>l91_sulu_form.type.selectmultiple</source>
<source>l91_sulu_form.type.dropdownmultiple</source>
<target>Select (multiple)</target>
</trans-unit>
<trans-unit id="34">
Expand Down

0 comments on commit 43e6b5d

Please sign in to comment.