From 6076c5aa02a0ba0abc4a018b8b61e1c42a94fb98 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Wed, 14 Feb 2024 09:44:02 -0500 Subject: [PATCH] Change the placeholder for the sluggable extension when generating a slug for an identifier field --- src/Sluggable/SluggableListener.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index f0b859080..a1bda53a9 100644 --- a/src/Sluggable/SluggableListener.php +++ b/src/Sluggable/SluggableListener.php @@ -257,7 +257,7 @@ public function prePersist(EventArgs $args) if ($config = $this->getConfiguration($om, $meta->getName())) { foreach ($config['slugs'] as $slugField => $options) { if ($meta->isIdentifier($slugField)) { - $meta->getReflectionProperty($slugField)->setValue($object, '__id__'); + $meta->getReflectionProperty($slugField)->setValue($object, uniqid('__sluggable_placeholder__')); } } } @@ -344,7 +344,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void $slug = $meta->getReflectionProperty($slugField)->getValue($object); // if slug should not be updated, skip it - if (!$options['updatable'] && !$isInsert && (!isset($changeSet[$slugField]) || '__id__' === $slug)) { + if (!$options['updatable'] && !$isInsert && (!isset($changeSet[$slugField]) || 0 === strpos($slug, '__sluggable_placeholder__'))) { continue; } // must fetch the old slug from changeset, since $object holds the new version @@ -352,7 +352,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void $needToChangeSlug = false; // if slug is null, regenerate it, or needs an update - if (null === $slug || '__id__' === $slug || !isset($changeSet[$slugField])) { + if (null === $slug || 0 === strpos($slug, '__sluggable_placeholder__') || !isset($changeSet[$slugField])) { $slug = ''; foreach ($options['fields'] as $sluggableField) {