Skip to content

Commit

Permalink
Merge pull request #1800 from bolt/fix/breakage-in-prod-for-select-fi…
Browse files Browse the repository at this point in the history
…elds

Fix breakage in PROD for `type: select` fields
  • Loading branch information
I-Valchev committed Sep 1, 2020
2 parents b5de232 + 0aa25b5 commit 81a4500
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Controller/Backend/ContentEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Bolt\Utils\TranslationsManager;
use Carbon\Carbon;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMInvalidArgumentException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -400,7 +401,11 @@ private function getFieldToUpdate(Content $content, string $fieldName, $fieldDef
// If the Field exists, but it has the wrong type, we'll remove the existing one.
if (($field !== null) && ! $content->hasField($fieldName, true)) {
$content->removeField($field);
$this->em->remove($field);
try {
$this->em->remove($field);
} catch (ORMInvalidArgumentException $e) {
// Suppress "Detached entity Array cannot be removed", because it'd break the Request
}
$this->em->flush();
$field = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function setAuthor(?User $author): void
$this->author = $author;
}

public function getStatus(): string
public function getStatus(): ?string
{
if (Statuses::isValid($this->status) === false) {
$this->status = $this->getDefinition()->get('default_status');
Expand Down
7 changes: 3 additions & 4 deletions src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Bolt\Entity\Field\Excerptable;
use Bolt\Entity\Field\ImageField;
use Bolt\Entity\Field\ImagelistField;
use Bolt\Entity\Field\SelectField;
use Bolt\Entity\Field\TemplateselectField;
use Bolt\Entity\Taxonomy;
use Bolt\Enum\Statuses;
Expand Down Expand Up @@ -502,7 +501,7 @@ public function pager(Environment $twig, ?Pagerfanta $records = null, string $te
return $twig->render($template, $context);
}

public function selectOptions(SelectField $field): LaravelCollection
public function selectOptions(Field $field): LaravelCollection
{
$values = $field->getDefinition()->get('values');

Expand All @@ -513,7 +512,7 @@ public function selectOptions(SelectField $field): LaravelCollection
return $this->selectOptionsContentType($field);
}

private function selectOptionsArray(SelectField $field): LaravelCollection
private function selectOptionsArray(Field $field): LaravelCollection
{
$values = $field->getDefinition()->get('values');
$currentValues = $field->getValue();
Expand Down Expand Up @@ -546,7 +545,7 @@ private function selectOptionsArray(SelectField $field): LaravelCollection
return new LaravelCollection($options);
}

private function selectOptionsContentType(SelectField $field): LaravelCollection
private function selectOptionsContentType(Field $field): LaravelCollection
{
[ $contentTypeSlug, $format ] = explode('/', $field->getDefinition()->get('values'));

Expand Down

0 comments on commit 81a4500

Please sign in to comment.