Skip to content

Commit

Permalink
fix(EntityGenerator): Fixed attributes list generator when there is o…
Browse files Browse the repository at this point in the history
…nly one attribute to print
  • Loading branch information
ambroisemaupate committed Mar 15, 2023
1 parent 5d34eb5 commit b6139ba
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/EntityGenerator/src/Attribute/AttributeListGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public function generate(int $currentIndentation = 0): string
return '';
}
if (count($this->attributes) === 1) {
return sprintf('#[%s]', reset($this->attributes)->generate($currentIndentation));
return sprintf(
'%s#[%s]',
str_repeat(' ', $currentIndentation),
reset($this->attributes)->generate()
);
}

return sprintf(
Expand Down
1 change: 0 additions & 1 deletion lib/EntityGenerator/src/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface;
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface;
use RZ\Roadiz\CoreBundle\Entity\UserLogEntry;
use RZ\Roadiz\EntityGenerator\Attribute\AttributeGenerator;
use RZ\Roadiz\EntityGenerator\Attribute\AttributeListGenerator;
use RZ\Roadiz\EntityGenerator\Field\AbstractFieldGenerator;
Expand Down
55 changes: 55 additions & 0 deletions lib/EntityGenerator/tests/mocks/GeneratedNodesSources/NSMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,61 @@ public function setFooBarSources(?array $fooBarSources): static
}


/**
* fooBarHiddenSources NodesSources direct field buffer.
* (Virtual field, this var is a buffer)
*
* ForBar hidden nodes field.
* Maecenas sed diam eget risus varius blandit sit amet non magna.
* @var \mock\Entity\NodesSources[]|null
*/
#[Serializer\Exclude]
private ?array $fooBarHiddenSources = null;

/**
* @return \mock\Entity\NodesSources[] fooBarHidden nodes-sources array
*/
#[
Serializer\Exclude,
SymfonySerializer\Ignore,
Serializer\VirtualProperty,
Serializer\SerializedName("fooBarHidden"),
Serializer\Type("array<mock\Entity\NodesSources>")
]
public function getFooBarHiddenSources(): array
{
if (null === $this->fooBarHiddenSources) {
if (
null !== $this->objectManager &&
null !== $this->getNode() &&
null !== $this->getNode()->getNodeType()
) {
$this->fooBarHiddenSources = $this->objectManager
->getRepository(\mock\Entity\NodesSources::class)
->findByNodesSourcesAndFieldAndTranslation(
$this,
$this->getNode()->getNodeType()->getFieldByName("foo_bar_hidden")
);
} else {
$this->fooBarHiddenSources = [];
}
}
return $this->fooBarHiddenSources;
}

/**
* @param \mock\Entity\NodesSources[]|null $fooBarHiddenSources
*
* @return $this
*/
public function setFooBarHiddenSources(?array $fooBarHiddenSources): static
{
$this->fooBarHiddenSources = $fooBarHiddenSources;

return $this;
}


/**
* fooBarTypedSources NodesSources direct field buffer.
* (Virtual field, this var is a buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,61 @@ public function setFooBarSources(?array $fooBarSources): static
}


/**
* fooBarHiddenSources NodesSources direct field buffer.
* (Virtual field, this var is a buffer)
*
* ForBar hidden nodes field.
* Maecenas sed diam eget risus varius blandit sit amet non magna.
* @var \mock\Entity\NodesSources[]|null
*/
#[Serializer\Exclude]
private ?array $fooBarHiddenSources = null;

/**
* @return \mock\Entity\NodesSources[] fooBarHidden nodes-sources array
*/
#[
Serializer\Exclude,
SymfonySerializer\Ignore,
Serializer\VirtualProperty,
Serializer\SerializedName("fooBarHidden"),
Serializer\Type("array<mock\Entity\NodesSources>")
]
public function getFooBarHiddenSources(): array
{
if (null === $this->fooBarHiddenSources) {
if (
null !== $this->objectManager &&
null !== $this->getNode() &&
null !== $this->getNode()->getNodeType()
) {
$this->fooBarHiddenSources = $this->objectManager
->getRepository(\mock\Entity\NodesSources::class)
->findByNodesSourcesAndFieldAndTranslation(
$this,
$this->getNode()->getNodeType()->getFieldByName("foo_bar_hidden")
);
} else {
$this->fooBarHiddenSources = [];
}
}
return $this->fooBarHiddenSources;
}

/**
* @param \mock\Entity\NodesSources[]|null $fooBarHiddenSources
*
* @return $this
*/
public function setFooBarHiddenSources(?array $fooBarHiddenSources): static
{
$this->fooBarHiddenSources = $fooBarHiddenSources;

return $this;
}


/**
* fooBarTypedSources NodesSources direct field buffer.
* (Virtual field, this var is a buffer)
Expand Down
8 changes: 8 additions & 0 deletions lib/EntityGenerator/tests/mocks/NodeTypeAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ protected function getMockNodeType()
->setLabel('ForBar nodes field')
->setDescription('Maecenas sed diam eget risus varius blandit sit amet non magna')
->setIndexed(false),
(new NodeTypeField())
->setName('foo_bar_hidden')
->setTypeName('nodes')
->setVirtual(true)
->setExcludedFromSerialization(true)
->setLabel('ForBar hidden nodes field')
->setDescription('Maecenas sed diam eget risus varius blandit sit amet non magna')
->setIndexed(false),
(new NodeTypeField())
->setName('foo_bar_typed')
->setTypeName('nodes')
Expand Down

0 comments on commit b6139ba

Please sign in to comment.