Compare commits

..

1 Commits

Author SHA1 Message Date
00e77aef62
[debug] 2023-05-07 01:26:23 +02:00
2 changed files with 13 additions and 5 deletions

View File

@ -20,13 +20,18 @@ abstract class ModelWithSlug extends Model
public function getSlug(): string public function getSlug(): string
{ {
if ($this->slug === null) {
$this->slug = $this->generateSlug();
var_dump('getSlug called');
var_dump($this->slug);
}
return $this->slug; return $this->slug;
} }
public function generateSlug(): string private function generateSlug(): string
{ {
$slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_')); $slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_'));
$this->slug = Slugify::create()->slugify($this->$slugSourceGetMethod()); return Slugify::create()->slugify($this->$slugSourceGetMethod());
return $this->slug;
} }
} }

View File

@ -113,6 +113,10 @@ class PersistentDataManager implements IPersistentDataManager
} }
} }
var_dump($original);
var_dump($modified);
var_dump($diff);
if (count($modified) > 0) { if (count($modified) > 0) {
if ($model instanceof ModelWithSlug && isset($modified['slug'])) { if ($model instanceof ModelWithSlug && isset($modified['slug'])) {
$modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']); $modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']);
@ -125,8 +129,7 @@ class PersistentDataManager implements IPersistentDataManager
} }
} else { } else {
if ($model instanceof ModelWithSlug) { if ($model instanceof ModelWithSlug) {
$slug = $model->generateSlug(); $modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']);
$modified['slug'] = $this->generateUniqueSlug($model, $slug);
} }
$modify->fill($modified); $modify->fill($modified);