Skip to content

Commit

Permalink
add default locale, add translations, add form element width field, a…
Browse files Browse the repository at this point in the history
…dd order field
  • Loading branch information
alexander-schranz committed Jun 12, 2016
1 parent 6449463 commit 3b590a5
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 135 deletions.
66 changes: 62 additions & 4 deletions Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,43 @@ public function getFieldDescriptors($locale, $filters)
[
'defaultTranslation' => new DoctrineJoinDescriptor(
'defaultTranslation',
Form::class . '.defaultTranslation'
Form::class . '.translations',
sprintf('defaultTranslation.locale = %s.defaultLocale', Form::class)
),
]
),
'public.title'
);

$fieldDescriptors['changed'] = new DoctrineCaseFieldDescriptor(
'changed',
new DoctrineDescriptor(
'translation',
'changed',
[
'translation' => new DoctrineJoinDescriptor(
'translation',
Form::class . '.translations',
sprintf('translation.locale = \'%s\'', $locale)
),
]
),
new DoctrineDescriptor(
'defaultTranslation',
'changed',
[
'defaultTranslation' => new DoctrineJoinDescriptor(
'defaultTranslation',
Form::class . '.translations',
sprintf('defaultTranslation.locale = %s.defaultLocale', Form::class)
),
]
),
'public.changed',
false,
false
);

return $fieldDescriptors;
}

Expand Down Expand Up @@ -141,13 +171,41 @@ public function cgetTemplateAction(Request $request)
'attachment',
'checkbox',
'choice',
'multiple-choice',
'multipleChoice',
];

$widths = [
[
'id' => 'full',
'name' => 'l91_sulu_form.width.full',
],
[
'id' => 'half',
'name' => 'l91_sulu_form.width.half',
],
[
'id' => 'one-third',
'name' => 'l91_sulu_form.width.one-third',
],
[
'id' => 'two-thirds',
'name' => 'l91_sulu_form.width.two-thirds',
],
[
'id' => 'one-quarter',
'name' => 'l91_sulu_form.width.one-quarter',
],
[
'id' => 'three-quarters',
'name' => 'l91_sulu_form.width.three-quarters',
],
];

return $this->render(
$this->getBundleName() . ':' . $this->getListName() . ':template.html.twig',
[
'types' => $types,
'widths' => $widths,
]
);
}
Expand Down Expand Up @@ -328,8 +386,8 @@ protected function getFilters(Request $request)
unset($filters['flat']);

$filters['fields'] = $listRestHelper->getFields();
$filters['limit'] = (int)$listRestHelper->getLimit();
$filters['offset'] = (int)$listRestHelper->getOffset();
$filters['limit'] = (int) $listRestHelper->getLimit();
$filters['offset'] = (int) $listRestHelper->getOffset();
$filters['sortColumn'] = $listRestHelper->getSortColumn();
$filters['sortOrder'] = $listRestHelper->getSortOrder();
$filters['searchFields'] = $listRestHelper->getSearchFields();
Expand Down
70 changes: 45 additions & 25 deletions Entity/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace L91\Sulu\Bundle\FormBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

class Form
{
/**
Expand All @@ -10,9 +12,9 @@ class Form
private $id;

/**
* @var FormTranslation
* @var string
*/
private $defaultTranslation;
private $defaultLocale;

/**
* @var \Doctrine\Common\Collections\Collection|FormTranslation[]
Expand All @@ -29,8 +31,8 @@ class Form
*/
public function __construct()
{
$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
$this->fields = new \Doctrine\Common\Collections\ArrayCollection();
$this->translations = new ArrayCollection();
$this->fields = new ArrayCollection();
}

/**
Expand All @@ -42,23 +44,19 @@ public function getId()
}

/**
* @param FormTranslation $defaultTranslation
*
* @return Form
* @return string
*/
public function setDefaultTranslation(FormTranslation $defaultTranslation = null)
public function getDefaultLocale()
{
$this->defaultTranslation = $defaultTranslation;

return $this;
return $this->defaultLocale;
}

/**
* @return FormTranslation
* @param string $defaultLocale
*/
public function getDefaultTranslation()
public function setDefaultLocale($defaultLocale)
{
return $this->defaultTranslation;
$this->defaultLocale = $defaultLocale;
}

/**
Expand Down Expand Up @@ -93,7 +91,7 @@ public function getTranslations()
* @param string $locale
* @param bool $create
*
* @return FormTranslation
* @return FormTranslation|null
*/
public function getTranslation($locale, $create = false)
{
Expand All @@ -103,12 +101,14 @@ public function getTranslation($locale, $create = false)
}
}

if ($create) {
$translation = new FormTranslation();
$translation->setLocale($locale);

return $translation;
if (!$create) {
return;
}

$translation = new FormTranslation();
$translation->setLocale($locale);

return $translation;
}

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ public function getFields()
* @param string $key
* @param bool $create
*
* @return FormField
* @return FormField|null
*/
public function getField($key, $create = false)
{
Expand All @@ -153,11 +153,31 @@ public function getField($key, $create = false)
}
}

if ($create) {
$field = new FormField();
$field->setKey($key);
if (!$create) {
return;
}

$field = new FormField();
$field->setKey($key);

return $field;
return $field;
}

/**
* @param $keys
*
* @return FormField[]
*/
public function getFieldsNotInArray($keys)
{
$fields = [];

foreach ($this->fields as $field) {
if (!in_array($field->getKey(), $keys)) {
$fields[] = $field;
}
}

return $fields;
}
}
85 changes: 57 additions & 28 deletions Entity/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace L91\Sulu\Bundle\FormBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

class FormField
{
/**
Expand Down Expand Up @@ -30,9 +32,14 @@ class FormField
private $id;

/**
* @var FormFieldTranslation
* @var int
*/
private $defaultTranslation;
private $order;

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

/**
* @var \Doctrine\Common\Collections\Collection|FormTranslation[]
Expand All @@ -49,7 +56,47 @@ class FormField
*/
public function __construct()
{
$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
$this->translations = new ArrayCollection();
}

/**
* @return string
*/
public function getDefaultLocale()
{
return $this->defaultLocale;
}

/**
* @param string $defaultLocale
*
* @return FormField
*/
public function setDefaultLocale($defaultLocale)
{
$this->defaultLocale = $defaultLocale;

return $this;
}

/**
* @return int
*/
public function getOrder()
{
return $this->order;
}

/**
* @param int $order
*
* @return FormField
*/
public function setOrder($order)
{
$this->order = $order;

return $this;
}

/**
Expand Down Expand Up @@ -140,23 +187,11 @@ public function getId()
return $this->id;
}

/**
* @param FormFieldTranslation $defaultTranslation
*
* @return FormField
*/
public function setDefaultTranslation(FormFieldTranslation $defaultTranslation = null)
{
$this->defaultTranslation = $defaultTranslation;

return $this;
}

/**
* @param string $locale
* @param bool $create
*
* @return FormFieldTranslation
* @return FormFieldTranslation|null
*/
public function getTranslation($locale, $create = false)
{
Expand All @@ -166,20 +201,14 @@ public function getTranslation($locale, $create = false)
}
}

if ($create) {
$translation = new FormFieldTranslation();
$translation->setLocale($locale);

return $translation;
if (!$create) {
return;
}
}

/**
* @return FormFieldTranslation
*/
public function getDefaultTranslation()
{
return $this->defaultTranslation;
$translation = new FormFieldTranslation();
$translation->setLocale($locale);

return $translation;
}

/**
Expand Down
1 change: 0 additions & 1 deletion EventListener/RequestListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace L91\Sulu\Bundle\FormBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
Expand Down
Loading

0 comments on commit 3b590a5

Please sign in to comment.