Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap list fields with 1 element in array #1396

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
}