Skip to content

Commit

Permalink
Merge pull request #1396 from bolt/bugfix/wrap-list-fields-with-1-ele…
Browse files Browse the repository at this point in the history
…ment-in-array

Wrap list fields with 1 element in array
  • Loading branch information
bobdenotter authored May 22, 2020
2 parents 2c7541a + 7fdd4db commit d79a26c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Entity/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function getParsedValue()
$count = count($value);
if ($count === 0) {
return null;
} elseif ($count === 1 && array_keys($value)[0] === 0) {
} elseif ($count === 1 && array_keys($value)[0] === 0 && ! $this instanceof ListFieldInterface) {
return reset($value);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/Field/FilelistField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Bolt\Configuration\Content\ContentType;
use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Bolt\Entity\ListFieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class FilelistField extends Field implements FieldInterface
class FilelistField extends Field implements FieldInterface, ListFieldInterface
{
public const TYPE = 'filelist';

Expand Down
5 changes: 3 additions & 2 deletions src/Entity/Field/ImagelistField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Bolt\Configuration\Content\ContentType;
use Bolt\Entity\Field;
use Bolt\Entity\FieldInterface;
use Bolt\Entity\ListFieldInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class ImagelistField extends Field implements FieldInterface
class ImagelistField extends Field implements FieldInterface, ListFieldInterface
{
public const TYPE = 'imagelist';

Expand All @@ -37,7 +38,7 @@ public function getValue(): array
$imageField = new ImageField();
$imageField->setName((string) $key);
$imageField->setValue($image);
array_push($result, $imageField);
$result[] = $imageField;
}

return $result;
Expand Down
12 changes: 12 additions & 0 deletions src/Entity/ListFieldInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Bolt\Entity;

/**
* Any Field that has an array of fields as its value must implement this interface.
*/
interface ListFieldInterface
{
}

0 comments on commit d79a26c

Please sign in to comment.