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

CiviCRM Menu -- Add PathProcessor to allow parameters to routes to include slashes #420

Merged
merged 10 commits into from
Jan 8, 2017
Merged

CiviCRM Menu -- Add PathProcessor to allow parameters to routes to include slashes #420

merged 10 commits into from
Jan 8, 2017

Conversation

jackrabbithanna
Copy link
Contributor

So Drupal 8 doesn't allow route parameters with slashes without some trickery.

You have to add a PathProcessor, and convert slashes to another character, in this case ':'

When we identify other paths that have parameters with slashes, we should add checks to the path processor and do a conversion....

@colemanw
Copy link
Member

colemanw commented Jan 7, 2017

In this case, there wasn't any particular reason for using slashes instead of the traditional ?arg1= so if it causes this much grief for D8 I'd vote to just change the path in CiviCRM core to something less weird.
On the server-side, all the args are ignored anyway, they are only there to prevent browser caching.

@colemanw
Copy link
Member

colemanw commented Jan 7, 2017

Here is an alternate solution: civicrm/civicrm-core#9650

@jackrabbithanna
Copy link
Contributor Author

From my perspective its six one way and half a dozen the other, just want to make a Drupal 8 integration possible work.

The only reason to use this PR and include a PathProcessor service, is if there are other paths which will need this handling.
ATM any civicrm path that take url components instead of ?arg style parameters will result in a 404 in Drupal

If there are other situations where it is not so convenient to change to using ?arg style parameters, something like this will need to be anyway....

@colemanw
Copy link
Member

colemanw commented Jan 7, 2017

One other that comes to mind is civicrm/admin/options/{option_group}.

@jackrabbithanna
Copy link
Contributor Author

I think it will be possible to automate CivicrmPathProcessor::processInbound()

For every path we can can check it to see if its a registered Civi route, but getting the menu items array with \CRM_Core_Menu::items()

If it is a civi path, then we look to see if there are additional path components, and if so, process them...

The controller mods will work already with this....

So maybe we can allow these url component params with any civi path, in one swoop...

This is what I had in mind with https://issues.civicrm.org/jira/browse/CRM-19843

@colemanw
Copy link
Member

colemanw commented Jan 7, 2017

@jackrabbithanna good plan! Go for it. 👍

@jackrabbithanna
Copy link
Contributor Author

all right, just made another commit, its working for the menu, and that should do it!

$items = \CRM_Core_Menu::items();
foreach (array_keys($items) as $item) {
// if he current path is a civicrm path
if(('/' . $item . '/') == $path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm reading it wrong but substituting values for variables this statement looks like if ('/civicrm/ajax/menujs/1/en_US/1/foo' == '/civicrm/ajax/menujs/') which would always evaluate to false.

@jackrabbithanna
Copy link
Contributor Author

ok, got an update commit....

Turns out you have to clear drupal caches every change you make to this file

This works for pages and the menu...

But submitting forms is doing somthing strange...

So if you go to the basic contact search:
and click "Find Contact", the results come up, but the path in the browser is:

Not sure if this is a problem in the Drupal code, or a different problem with drupal code, or something else entirely...

civicrm/contact/search//civicrm/contact/search?_qf_Basic_display=true&qfKey=9ecd43b2ffe43cd2c4eff2d83ee153aa_8904

@jackrabbithanna
Copy link
Contributor Author

ok think I got it now, menu works, pages work, forms work....

@colemanw
Copy link
Member

colemanw commented Jan 8, 2017

Cool. And did you try it with e.g. /civicrm/admin/options/activity_type?reset=1?

@jackrabbithanna
Copy link
Contributor Author

yes that path works, and since I got that last commit I've been using the site, and all the ajax everywhere seems to be working great. In fact in Drupal 8 it seems quite a bit faster to me than Drupal 7....Its nice

@jackrabbithanna
Copy link
Contributor Author

I'm using the yesterday's 4.7 master tarball...

The API explorer gives a javascript error on page load, and in the firebug console i see:
TypeError: _ is undefined
fieldTpl = _.template($('#api-param-tpl').html()),

What do you think causes that?

@colemanw
Copy link
Member

colemanw commented Jan 8, 2017

@jackrabbithanna this is a bug in D8 only?
_ should be a reference to the CRM._ variable. Try typing that in your console (CRM dot underscore) and see what you get.

@jackrabbithanna
Copy link
Contributor Author

There are javascript related errors on several pages. Both the contribution page and event edit pages complain about missing Backbone...
Several other pages have jQuery related errors...
I don't think that these things are related to the routing problem in this PR

@jackrabbithanna
Copy link
Contributor Author

and its not that the backbone script isn't loading, it is...

Civicrm adds its js into the head (backbone 1.0.) , and drupal is adding a different version before the end of the closing body tag (1.2.3)

Will probably make a separate issue in JIRA for javascript stuff, and we may have to do some juggling to make sure civicrm can make use of the version it needs....

@colemanw colemanw merged commit 42ae663 into civicrm:8.x-master Jan 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants