Summary
This is a simple but powerful module for Drupal 7 & Views 3.x to convert a view argument's node id into its url path.
There is a similar solution for terms in views core, however there is no in-code solution to handle contextual filters for nid. One possible solution is to use in-line PHP in the contextual filter, but I really don't like in-line PHP and when I created this module, I did so because we use that same logic in several different views. Developing this into a module means there is less code in the world.
Project Page
Git Repository
git clone http://git.drupal.org/sandbox/lucashedding/1872408.git views_url_path_arguments
Requirements
Installation
Install as usual. See Installing contributed modules (Drupal 7) for further information.
Configuration
- Configure contextual filters in Administration » Structure » Views » view:
- Add a contextual filter i.e. Content: Nid
- When the filter value is available or a default is provided » Specify validation criteria: Url path alias
Review for this Project
http://ventral.org/pareview/httpgitdrupalorgsandboxlucashedding1872408git
Reviews of Other Projects
More coming soon... BTW, these reviews are really fun! I'm might have to start doing more of them when I get a free moment.
- https://drupal.org/node/1884178#comment-7018122
- https://drupal.org/node/1857052#comment-7018440
- https://drupal.org/node/1721378#comment-7018542
- http://drupal.org/node/1884380#comment-7034282
- http://drupal.org/node/1867346#comment-7034694
- http://drupal.org/node/1781984#comment-7034954
- http://drupal.org/node/1893226#comment-7043264
- http://drupal.org/node/1740956#comment-7043458
- http://drupal.org/node/1909634#comment-7043528
Comments
Comment #1
vladimir-m commentedHello heddn,
Thank you for great module.
1. Please add git link corresponding to non-maintainer like "git clone http://git.drupal.org/sandbox/lucashedding/1872408.git views_url_path_arguments"
2.Please review your module from coder module and see the automated code review http://ventral.org/pareview/httpgitdrupalorgsandboxlucashedding1872408git
3.I suggest you to use in file: views_plugin_argument_validate_url_path.inc at line: 19, 31, function is_object() to check variable is an object.
Cheers!
Comment #2
vladimir-m commentedComment #3
alexmoreno commentedAs a recommendation, do at least three reviews of other modules to accelerate your process of approval.
I will check when I come back home, but the code seems too short to be considered for approval, please confirm because and in a mobile smartphone and I cannot download the code just now. Using drupalcode.org shows really few lines of code, maybe I am wrong (again, I will check in a few days, I'm just traveling).
Thank you for your effort.
Comment #4
heddnThanks for all the great feedback.
Comment: #2
Comment: #3
Comment #4.0
heddnUpdated issue summary.
Comment #4.1
heddnUpdated issue summary.
Comment #4.2
heddnUpdated issue summary.
Comment #5
heddnPAReview: review bonus
Comment #6
heddnFor #4#2-3, I probably should change this back to
if (!$node)because the interface for node_load is to return an object or FALSE. Why add all the extra overhead (though minimal) ofis_object()?Comment #7
klausimanual review:
Otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #8
heddnI'm working on adding a new feature to handle blocks i.e. views_plugin_argument_default. And will also beef up the project description with a more clear use case. This will hopefully push things over the 120 line / 5 method limit.
Comment #9
heddnNew features added and README / project page updated.
Comment #9.0
heddnUpdated issue summary.
Comment #9.1
heddnUpdated issue summary.
Comment #9.2
heddnUpdated issue summary.
Comment #10
heddnAdded more lines of code and performed additional reviews.
Comment #11
heddnI'd like to get this module promoted through the normal processes.
Comment #12
tsphethean commentedAutomated review looks good except for the naming convention issue discussed earlier.
README and Project page are now both more descriptive and describe the purpose/use case of the module.
Multiple reviews completed by the author with good comments.
The only thing I think which definitely needs looking at is that in views_plugin_argument_default_url_path(),
could be simplified to:
although even with this, there is a potential scenario where nothing will be returned - does this cause views any problems if drupal_lookup_path returns false for any reason? Alternatively if we're always going to get something relevant back from drupal_lookup_path then could do:
Shouldn't stop approval but worth considering:
In validate_argument() in views_plugin_argument_validate_url_path, there are a couple of node loads. I can't decide if these are necessary, or if there should just be a query against the node table to check if the argument is a valid nid - it doesnt need to load the whole node as it only returns TRUE/FALSE, which for some node types with CCK fields etc could involve expensive queries (admittedly statically cached). You may at least be able to cut out the first node load. Don't think it's a show stopper in any case, but interesting to think about.
Comment #13
tsphethean commentedDuplicate submission. Deleting
(I've done this a lot today. Comment button doesnt seem to be indicating its been clicked very well :-( )
Comment #14
heddn#12
Default argument plugin: The way it is working is correct. If nothing validates, then it uses the views default value of 'all'.
Validate argument plugin: You bring up a good point. I don't really need to perform a node_load(). I've switched it to do a query against the node table and that should be sufficient. I've also reworked the function to return a single value at the bottom of the function. That makes the code a lot more clear in the validate plugin.
Comment #15
tsphethean commenteddefault argument plugin - understand, the simplified return values look good though and make the code much easier, good stuff.
validate argument plugin - I think you still needed the second node_load (after
elseif ($nid = drupal_lookup_path('source', $argument)) {) as now $node->nid and $node->title are undefined and will throw warnings/not set correctly (unless you're dispensing with that info?).For the query against the node table when nid is numeric, we should use db_select for D7 for compatability against other DB backends, so your syntax would be something like:
Comment #16
heddn#15 - Good point about $node->nid & title. That is now fixed.
Explain more about using db_select vs db_query. I've never heard that argument for use of db_select. I almost always use db_query because it is more performant than db_select. Can you point me to some references on when to use one vs the other?
Comment #17
heddnComment #18
tsphethean commentedHere's a good answer on when to use db_query vs db_select: http://drupal.stackexchange.com/questions/1200/given-that-db-select-is-m...
Having said that, it does look like running through that list this use case is pretty ok for using db_query so its up to you. If you stick with db_query though, make sure to enclose the table name in {} i.e.
SELECT COUNT(*) FROM {node} WHERE nid = :nid LIMIT 1I'd also add a limit, it won't make a massive difference as you're querying an indexed column with unique key on nid, but every little helps IMO.
Comment #19
heddn#18 - nid is a primary key so it is certain to only return a single result or FALSE. I found the article that explains why you should use {} around table names. It's for multi-site installs. See prefixing: http://drupal.org/node/310072. This issue is also now fixed & committed.
Comment #20
tsphethean commentedChanges look good to me. Happy to mark this as RTBC and see if anyone disagrees.
Good work, and a good module.
Comment #21
tsphethean commentedComment #22
klausimanual review:
Could be a potential security issue, so I set this back to needs work to hear your opinion. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #23
heddn#22 - Good point, these things should honor node_access. I'm not certain if its a security issue but at the very least, changing to db_select will give a more consistent user experience. At the most, a node title could have been exposed. I couldn't prove that unless I did more testing. Regardless, I've switched to using db_select() for UX reasons.
Comment #24
heddnComment #24.0
heddnUpdated issue summary.
Comment #24.1
heddnUpdated issue summary.
Comment #24.2
heddnUpdated issue summary.
Comment #25
heddnre-added bonus
Comment #26
klausiVery good, looks RTBC to me now.
Comment #27
patrickd commentedheyho
I personally don't think that a hook_help() that provides just the same information as the module description ... is really helpful. Maybe you could provide more information? eg. A more detailed example how-to? it took a while until I really understood how to use it.
But there's nothing critical and also your reviews show that you are experienced enough to get approved!
Many thanks for your contribution and reviews!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #28.0
(not verified) commentedUpdated issue summary.