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

Fix issues with wrong view name in frontend helper #920

Merged
merged 1 commit into from
May 21, 2021

Conversation

ptrckvzn
Copy link
Member

@ptrckvzn ptrckvzn commented May 21, 2021

Description

View name in frontend helper was returning broken view path.

twillViewName was returning "'admin.'.pages.'.create'" instead of "admin.pages.create".

Related Issues

@ptrckvzn ptrckvzn requested review from antonioribeiro and ifox and removed request for antonioribeiro May 21, 2021 14:18
@antonioribeiro antonioribeiro self-requested a review May 21, 2021 17:23
@antonioribeiro
Copy link
Member

Those quotes are there because the code will generate Blade compiled code (PHP).

So it generates something like

<php

echo twillViewName('admin.posts.form');

If we remove the quotes, the final code will be

<php

echo twillViewName(admin.posts.form);

Generating an execution error because PHP would try to find an admin constant that doesn't exists.

@ptrckvzn
Copy link
Member Author

ptrckvzn commented May 21, 2021

@antonioribeiro The PHP generated by the directive looks like this.

if( view()->exists(twillViewName(($moduleName ?? null), 'create'))) {

It's the ($moduleName ?? null) expression that is being output from the directive and passed to twillViewName when the view is called. So it will evaluate the string returned from twillViewName but won't interpolate variables in it.

view()->exists(twillViewName(($moduleName ?? null), 'create')) with the returned string -> view()->exists('admin.pages.create')

It stills feels correct to me to return a string from twillViewName without expecting variables interpolation.

@antonioribeiro
Copy link
Member

You are right, @ptrckvzn. The fist view()->exists($view) will never be able to find a view because of those quotes. Good catch!

@ifox ifox merged commit d73f00a into area17:2.x May 21, 2021
@ptrckvzn ptrckvzn deleted the fix/create-form-bug branch May 24, 2021 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants