diff --git a/config/bolt/config.yaml b/config/bolt/config.yaml index d6825af18..e91d7402f 100644 --- a/config/bolt/config.yaml +++ b/config/bolt/config.yaml @@ -114,7 +114,6 @@ search_results_records: 10 # for each content type. records_per_page: 8 - # Default settings for thumbnails. # # quality: Quality should be between 0 (horrible, small file) and 100 (best, huge file). diff --git a/src/Entity/Content.php b/src/Entity/Content.php index 6a72d49d5..6941c7a05 100644 --- a/src/Entity/Content.php +++ b/src/Entity/Content.php @@ -155,7 +155,7 @@ public function __construct(?ContentType $contentTypeDefinition = null) public function __toString(): string { - $contentName = $this->getDefinition() ? $this->getContentTypeName() : 'Content'; + $contentName = $this->getDefinition() ? $this->getContentTypeSingularName() : 'Content'; if ($this->getId()) { return sprintf('%s #%d', $contentName, $this->getId()); } @@ -283,6 +283,15 @@ public function getContentTypeName(): string throw new \RuntimeException('Content not fully initialized'); } + return $this->getDefinition()->get('name') ?: $this->getContentTypeSlug(); + } + + public function getContentTypeSingularName(): string + { + if ($this->getDefinition() === null) { + throw new \RuntimeException('Content not fully initialized'); + } + return $this->getDefinition()->get('singular_name') ?: $this->getContentTypeSlug(); } diff --git a/src/Event/Listener/ContentFillListener.php b/src/Event/Listener/ContentFillListener.php index a6300b980..cbb619718 100644 --- a/src/Event/Listener/ContentFillListener.php +++ b/src/Event/Listener/ContentFillListener.php @@ -13,7 +13,6 @@ use Bolt\Repository\UserRepository; use Bolt\Twig\ContentExtension; use Doctrine\ORM\Event\LifecycleEventArgs; -use RuntimeException; class ContentFillListener { @@ -58,7 +57,7 @@ public function prePersist(LifecycleEventArgs $args): void if ($entity instanceof Content) { if ($entity->getAuthor() === null) { - $entity->setAuthor($this->guesstimateAuthor($entity->getContentTypeName())); + $entity->setAuthor($this->guesstimateAuthor()); } if ($entity->getPublishedAt() === null && $entity->getStatus() === Statuses::PUBLISHED) { @@ -82,14 +81,8 @@ public function fillContent(Content $entity): void $entity->setContentExtension($this->contentExtension); } - private function guesstimateAuthor($contenttype): User + private function guesstimateAuthor(): User { - $user = $this->users->getFirstAdminUser(); - - if ($user === null) { - throw new RuntimeException('Error persisting record of type ' . $contenttype . ' without author. Could not guesstimate author.'); - } - - return $user; + return $this->users->getFirstAdminUser(); } }