Skip to content

Commit

Permalink
Change the placeholder for the sluggable extension when generating a …
Browse files Browse the repository at this point in the history
…slug for an identifier field
  • Loading branch information
mbabker authored and franmomu committed Jun 9, 2024
1 parent ec47681 commit b31d2cf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Sluggable/SluggableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__'));
}
}
}
Expand Down Expand Up @@ -344,15 +344,15 @@ 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
$oldSlug = isset($changeSet[$slugField]) ? $changeSet[$slugField][0] : $slug;
$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) {
Expand Down

0 comments on commit b31d2cf

Please sign in to comment.