Skip to content

Commit

Permalink
Merge tag v2.3.16 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Jul 2, 2024
1 parent 7334df9 commit 775bce3
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"ramsey/uuid": "^4.7",
"rezozero/intervention-request-bundle": "~3.0.0",
"rezozero/liform-bundle": "^0.19",
"rezozero/tree-walker": "^1.3.0",
"rezozero/tree-walker": "^1.5.0",
"roadiz/doc-generator": "2.4.x-dev",
"roadiz/documents": "2.4.x-dev",
"roadiz/dts-generator": "2.4.x-dev",
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version20240702205419.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240702205419 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added autocomplete field to custom_form_fields table.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE custom_form_fields ADD autocomplete VARCHAR(18) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE custom_form_fields DROP autocomplete');
}
}
52 changes: 51 additions & 1 deletion src/Entity/CustomFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use RZ\Roadiz\CoreBundle\Repository\CustomFormFieldRepository;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation as SymfonySerializer;
use RZ\Roadiz\Core\AbstractEntities\AbstractField;
use Symfony\Component\Validator\Constraints\Choice;

/**
* CustomFormField entities are used to create CustomForms with
* custom data structure.
*/
#[
ORM\Entity(repositoryClass: "RZ\Roadiz\CoreBundle\Repository\CustomFormFieldRepository"),
ORM\Entity(repositoryClass: CustomFormFieldRepository::class),
ORM\Table(name: "custom_form_fields"),
ORM\UniqueConstraint(columns: ["name", "custom_form_id"]),
ORM\Index(columns: ["position"]),
Expand Down Expand Up @@ -73,6 +75,43 @@ class CustomFormField extends AbstractField
]
private bool $required = false;

/**
* @var string|null https://developer.mozilla.org/fr/docs/Web/HTML/Attributes/autocomplete
*/
#[
ORM\Column(name: "autocomplete", type: 'string', length:18, nullable: true),
Serializer\Groups(["custom_form"]),
SymfonySerializer\Groups(["custom_form"]),
Choice([
'off',
'name',
'honorific-prefix',
'honorific-suffix',
'given-name',
'additional-name',
'family-name',
'nickname',
'email',
'username',
'organization-title',
'organization',
'street-address',
'country',
'country-name',
'postal-code',
'bday',
'bday-day',
'bday-month',
'bday-year',
'sex',
'tel',
'tel-national',
'url',
'photo',
])
]
private ?string $autocomplete = null;

public function __construct()
{
parent::__construct();
Expand Down Expand Up @@ -132,6 +171,17 @@ public function setRequired(bool $required): CustomFormField
return $this;
}

public function getAutocomplete(): ?string
{
return $this->autocomplete;
}

public function setAutocomplete(?string $autocomplete): CustomFormField
{
$this->autocomplete = $autocomplete;
return $this;
}

/**
* @return string
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/NodesTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
use JMS\Serializer\Annotation as Serializer;
use RZ\Roadiz\Core\AbstractEntities\PositionedInterface;
use RZ\Roadiz\Core\AbstractEntities\PositionedTrait;
use RZ\Roadiz\CoreBundle\Repository\NodesTagsRepository;
use Symfony\Component\Serializer\Annotation as SymfonySerializer;

#[
ORM\Entity,
ORM\Entity(repositoryClass: NodesTagsRepository::class),
ORM\Table(name: "nodes_tags"),
ORM\Index(columns: ['node_id', 'position'], name: 'nodes_tags_node_id_position'),
ORM\Index(columns: ['tag_id', 'position'], name: 'nodes_tags_tag_id_position'),
Expand Down
12 changes: 8 additions & 4 deletions src/Form/CustomFormsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
],
];

if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['attr']['placeholder'] = $field->getPlaceholder();
}

if ($field->getAutocomplete() !== null) {
$option['attr']['autocomplete'] = $field->getAutocomplete();
}

if ($field->isRequired()) {
$option['required'] = true;
$option['constraints'] = [
Expand All @@ -198,7 +202,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
$option["format"] = DateType::HTML5_FORMAT;
break;
case AbstractField::ENUM_T:
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
$option["choices"] = $this->getChoices($field);
Expand All @@ -212,7 +216,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
}
break;
case AbstractField::MULTIPLE_T:
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
$option["choices"] = $this->getChoices($field);
Expand Down Expand Up @@ -255,7 +259,7 @@ protected function getOptionsForField(CustomFormField $field, array $formOptions
break;
case AbstractField::COUNTRY_T:
$option["expanded"] = $field->isExpanded();
if ($field->getPlaceholder() !== '') {
if (!empty($field->getPlaceholder())) {
$option['placeholder'] = $field->getPlaceholder();
}
if (!empty($field->getDefaultValues())) {
Expand Down
12 changes: 12 additions & 0 deletions src/Repository/CustomFormFieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace RZ\Roadiz\CoreBundle\Repository;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\CustomForm;
use RZ\Roadiz\CoreBundle\Entity\CustomFormField;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand All @@ -17,4 +18,15 @@ public function __construct(ManagerRegistry $registry, EventDispatcherInterface
{
parent::__construct($registry, CustomFormField::class, $dispatcher);
}

public function findDistinctGroupNamesInCustomForm(CustomForm $customForm): array
{
$qb = $this->createQueryBuilder('o');
$qb->select('DISTINCT o.groupName')
->andWhere($qb->expr()->eq('o.customForm', ':customForm'))
->setParameter('customForm', $customForm);

$result = $qb->getQuery()->getResult();
return array_map(fn (array $row) => $row['groupName'], $result);
}
}
22 changes: 22 additions & 0 deletions src/Repository/NodesTagsRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Repository;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\NodesTags;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* @extends EntityRepository<NodesTags>
*/
class NodesTagsRepository extends EntityRepository
{
public function __construct(
ManagerRegistry $registry,
EventDispatcherInterface $dispatcher
) {
parent::__construct($registry, NodesTags::class, $dispatcher);
}
}

0 comments on commit 775bce3

Please sign in to comment.