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

Fix breakage in PROD for type: select fields #1800

Merged
merged 3 commits into from
Sep 1, 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
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