diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index f0b8590807..a1bda53a95 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) {