From 94e4570968d8b3810bd5954491a6531414eb881e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EA=B4=80=EC=98=81?= Date: Tue, 16 Jan 2018 11:00:48 +0900 Subject: [PATCH] Fix TaggableTrait utf8_slug test failure --- Modules/Core/helpers.php | 21 --------------------- Modules/Tag/Traits/TaggableTrait.php | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Modules/Core/helpers.php b/Modules/Core/helpers.php index 43ad43534..6c1cd5c9e 100644 --- a/Modules/Core/helpers.php +++ b/Modules/Core/helpers.php @@ -54,24 +54,3 @@ function asgard_editor($fieldName, $labelName, $content) return view('core::components.textarea-wrapper', compact('fieldName', 'labelName', 'content')); } } - -if (! function_exists('utf8_slug')) { - function utf8_slug($title, $separator = '-') - { - // Convert all dashes/underscores into separator - $flip = $separator == '-' ? '_' : '-'; - - $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); - - // Replace @ with the word 'at' - $title = str_replace('@', $separator.'at'.$separator, $title); - - // Remove all characters that are not the separator, letters, numbers, or whitespace. - $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); - - // Replace all separator characters and whitespace by a single separator - $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); - - return trim($title, $separator); - } -} diff --git a/Modules/Tag/Traits/TaggableTrait.php b/Modules/Tag/Traits/TaggableTrait.php index 267f9945f..b8dcbca71 100644 --- a/Modules/Tag/Traits/TaggableTrait.php +++ b/Modules/Tag/Traits/TaggableTrait.php @@ -204,8 +204,22 @@ protected function getEntityClassName() /** * {@inheritdoc} */ - protected function generateTagSlug($name) + protected function generateTagSlug($name, $separator = '-') { - return utf8_slug($name); + // Convert all dashes/underscores into separator + $flip = $separator == '-' ? '_' : '-'; + + $name = preg_replace('!['.preg_quote($flip).']+!u', $separator, $name); + + // Replace @ with the word 'at' + $name = str_replace('@', $separator.'at'.$separator, $name); + + // Remove all characters that are not the separator, letters, numbers, or whitespace. + $name = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($name)); + + // Replace all separator characters and whitespace by a single separator + $name = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $name); + + return trim($name, $separator); } }