Closed (fixed)
Project:
Feeds XPath Parser
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Mar 2013 at 10:25 UTC
Updated:
16 Jul 2014 at 12:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ndobromirov commentedAdded the hook implementation.
Comment #2
ndobromirov commentedAdded more context information to the filtering hook. The previous patch can be ignored.
Comment #3
ndobromirov commentedThe last patch generates variable name conflicts within the parse method. Adding a new patch to fix the issue.
Comment #4
twistor commentedI'd be curious to know what your use case is, have you seen Feeds Tamper?
Why is this being changed? I don't follow.
checked
TRUE
Comment #5
twistor commentedComment #6
ndobromirov commentedThanks for the review.
Answer of Q1:
I am using feeds tamper, but it is a tool for additional processing of mapped field(s). Correct me if something more can be done with it.
My use case is that I want to filter the context nodes before passing them for processing with feeds tamper.
Normally this is implemented with the "Context" XPath expression in the parser settings, but in my case the expression is becoming too large, complex with a lot of sub-expression repetitions within it - hard to maintain/change. In some of the use cases I need to be able to use node set manipulations like intersection and subtraction when XPath 1.0 allows only union with the "|" syntax.
This is the reason that a hook was implemented, with some PHP code all of the above was solved in a matter of 2-3 screens of code.
Answer of Q2:
The parameter name $source in the original implementation needs to be of type FeedsSource and it is passed as additional context information to the filtering hook. Part of the process method without rename of the variable would look like this:
The inner loop defines iteration key variable with the same name as the parameter, replacing the FeedsSource with a string on the first iteration, making the call to the filtering hook with wrong source context in the second iteration of the outer loop.
Answer of Q3:
Thanks, for spotting the typo.
Answer of Q4:
Will fix the constants to the convention specs.
Comment #7
twistor commented1. That is true. Feeds Tamper can do filtering, but you lose the context of the XML. I am familiar with how unruly the XPath expressions can get. Could we call the hook 'feeds_xpathparser_filter_domnode' or something so that it's not confused with node.module? Maybe pass in the DOMDocument as well so you could do more than just filter, like append children or something.
2. Good catch. I'm surprised this hasn't caused trouble already. Not to be picky, but we should leave $source in the function signature, and change
foreach ($source_config['sources'] as $source => $query) {toforeach ($source_config['sources'] as $element_key => $query) {. The $source in the function is pretty standard.You might also be interested in #1846956: Allow using safe PHP functions.
Comment #8
ndobromirov commentedThanks for the fast response.
1. I will rename the hook and add the document parameter.
2. I will do the refactoring and upload a patch with all the discussed fixes.
Best regards,
Nikolay D.
Comment #9
ndobromirov commentedAdding the patch fixing the issues discussed.
Comment #10
twistor commentedThanks.
http://drupalcode.org/project/feeds_xpathparser.git/commit/fbbc659
Comment #11
osopolarTODO: The hook hook_feeds_xpathparser_filter_domnode() needs to be documented somewhere - for example in a README.txt.
Comment #12
jenlamptonAlso could be useful for documentation...
If you want to actually *see* the DOMNode you need to do this...
Comment #13
twistor commentedWould something like this work?
Words are hard.
Comment #14
osopolarLooks nice, thanks @twistor.
Comment #16
twistor commentedComment #17
twistor commented6.x usage is declining slowly. If anyone feels like backporting go ahead.