Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

@slugify-title doesn't work in custom page creation modal [Admin plugin]

Started by Alexander Kim 8 years ago · 1 replies · 524 views
8 years ago

Using this recipe: Custom page creation modal

And setting language in supported languages (single language) results in a bug, i can't create a new page using these modals from recipe, because slug didn't work for Cyrillic symbols.

8 years ago

Here's workaround for people, who will experience the same issue:

File location: /user/plugins/admin/classes/utils.php

PHP
    public static function slug($str)
    {

        //Cyrillic
        $contains_cyrillic = (bool) preg_match('/[\p{Cyrillic}]/u', $str);
        if ($contains_cyrillic) {
            $cyr = [
                'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п',
                'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',
                'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П',
                'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я',
                // Kazakh letters
                'ә','ғ','қ','ң','ө','ұ','ү','һ','і'
            ];
            $lat = [
                'a','b','v','g','d','e','e','zh','z','i','y','k','l','m','n','o','p',
                'r','s','t','u','f','h','c','ch','sh','sh','a','i','y','e','yu','ya',
                'A','B','V','G','D','E','Io','Zh','Z','I','Y','K','L','M','N','O','P',
                'R','S','T','U','F','H','Ts','Ch','Sh','Sht','A','I','Y','e','Yu','Ya',
                // Kazakh letters
                'a','gh','q','ng','o','u','u','h','i'
            ];
            $str = str_replace($cyr, $lat, $str);
        }

        if (function_exists('transliterator_transliterate')) {
            $str = transliterator_transliterate('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;', $str);
        } else {
            $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
        }

        $str = strtolower($str);
        $str = preg_replace('/[-\s]+/', '-', $str);
        $str = preg_replace('/[^a-z0-9-]/i', '', $str);
        $str = trim($str, '-');

        return $str;
    }
👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 82 10 hours ago
General · by pamtbaau, 16 hours ago
1 53 15 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 347 5 days ago
General · by Duc , 5 days ago
3 41 5 days ago