-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
We have one special case in which we need to take the english translation instead of the japanese or chinese title of a profile. I couldn't find a better way to inject the logic required for this than extending the behavior and overriding the slug method:
class WaSlugBehavior extends SlugBehavior {
/**
* Generates slug.
*
* @param \Cake\ORM\Entity|string $entity Entity to create slug for
* @param string $string String to create slug for.
* @param string $separator Separator.
* @return string Slug.
*/
public function slug($entity, $string = null, $separator = '-') {
if ($entity instanceof EntityInterface
&& $entity->get('language_id') === LanguagesTable::JAPANESE
&& !empty($entity->get('translations'))
) {
foreach ($entity->get('translations') as $translation) {
if ($translation->get('locale') === LanguagesTable::ENGLISH) {
$entity = $translation->get('profile_title');
$string = null;
break;
}
}
}
return parent::slug($entity, $string, $separator);
}
}A simple solution might be to make the display field option taking a callable as well?
Any other suggestion is welcome.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels