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

Change the placeholder for the sluggable extension when generating a slug for an identifier field #2768

Merged
merged 1 commit into from
Jun 9, 2024
Merged
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
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
Loading