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

Methods get and item don't work with utf8 titles #264

Open
dlnsk opened this issue Feb 27, 2020 · 9 comments
Open

Methods get and item don't work with utf8 titles #264

dlnsk opened this issue Feb 27, 2020 · 9 comments

Comments

@dlnsk
Copy link

dlnsk commented Feb 27, 2020

\Menu::get('sbMenu')->get('Пользователи'); // means Users
\Menu::get('sbMenu')->item('Пользователи');
gets null

@dustingraham
Copy link
Collaborator

        Menu::make('sbMenu', function(){});
        Menu::get('sbMenu')->add('Пользователи');
        $x = Menu::get('sbMenu')->get('Пользователи');
        dd($x);

Seems to work for me. Did you add Пользователи to the menu first?

@dlnsk
Copy link
Author

dlnsk commented Feb 28, 2020

Yes. Of course.
I have copied your example and it is still buggy. If I change Пользователи to something in English it starts to work as expected.

PHP 7.3

@dustingraham
Copy link
Collaborator

What do you mean by still buggy? Are you inspecting the results of each get and add? I wouldn't be surprised if it's not utf8 friendly, but I don't know what needs to be changed. I tried the example I provided and it returned a menu item in $x

@dlnsk
Copy link
Author

dlnsk commented Feb 28, 2020

Menu::make('sbMenu', function(){});
$m = Menu::get('sbMenu')->add('Пользователи');
$x = Menu::get('sbMenu')->get('Пользователи');

If I use dd($m), I see Item object, but if dd($x) it returns null. If I change Пользователи to qwerty both variables contain Item.

@dustingraham
Copy link
Collaborator

Strange, that's exactly what I tried. I wonder if there are other differences in my php configuration. Have you seen this before, is there any common technique or shortfall of supporting utf8?

@dlnsk
Copy link
Author

dlnsk commented Feb 28, 2020

0 => Item {#570 ▼
        #builder: Builder {#671}
        #id: "id-5e58a7a4ba749253778274"
        +title: "Пользователи"
        +beforeHTML: null
        +afterHTML: null
        +nickname: "polzovateli"
        +divider: []
        #parent: null
        #link: Link {#613 ▶}
        #data: []
        #active: false
        +attributes: []
        +isActive: false
        -disableActivationByURL: false
      }

This is because you search in nickname.

    public function get($title)
    {
        return $this->whereNickname($title)->first();
    }

@dustingraham
Copy link
Collaborator

I suppose you could set the nickname manually. ->nickname('Пользователи') but, yes the search by nickname is pretty core to this package. If we change that, it could break many implementations.

Based on your findings, if you try ->get('polzovateli') it will probably retrieve the item (just as proof of concept.)

@dlnsk
Copy link
Author

dlnsk commented Feb 28, 2020

Based on your findings, if you try ->get('polzovateli') it will probably retrieve the item (just as proof of concept.)

Transliteration is a magic because nobody know how it converts cyrilic text. :)

I suppose you could set the nickname manually. ->nickname('Пользователи') but, yes the search by nickname is pretty core to this package. If we change that, it could break many implementations.

I think you should improve documentation because now it explicitly says Get Item by Title and not describe principle of operation of get and item.
For support backward compatibles I offer to add method getByTitle because to add nicknames manually to all items seems not convenient especially if using automatic generation.

@dustingraham
Copy link
Collaborator

Both good ideas, and good points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants