0
votes

I have a simple content type that has a "parent" field on every content type. This parent field is shown by an entity reference in each of the other associated content types. If there is a parent content type then you can associate these other content types to it.

Using views, I have page that shows all the results of "notes" for example. Notes has a parent associated with it that must be selected when you create a new note. So every note has a parent.

I have been attempting to show all the notes of a certain parent through the URL like so (i have pathauto and alias' setup):

committees/parent/notes

Using contextual filters and entity reference (parent) I am attempting to show these notes based on parent context. I have under relationships: Entity Reference: Parent and under Contextual filters (Content entity referenced from field_parent) Content: Parent. When I preview this in the auto preview area, nothing shows. For example a parent name is "fire" and I enter it in the preview contextual filter and nothing shows.

I have it setup like so:

When the filter value IS NOT in the URL:

Checked Provide Default Value

Type: Raw Value from URL (URL is committees/parent/notes)

Path Component: 2 (parent)

Checked - Use Path Alias

When the filter value IS in the URL or Default Provided:

Checked - Specify Validation Criteria

Selected - Validator: PHP Code

PHP Validate Code:**

$handler->argument = str_replace("-"," ",$argument);
return true;

However using Contextual filters (Content entity referenced from field_parent) Content: Nid and then put in the node id of the parent (fire in this case), I am able to see the notes for "fire" for the certain parent node id (which is the same as fire just the nid). This is exactly what I want.

What am I missing here for the parent to be referenced in the URL and show the notes based on that parent? Why does the NID work and not the PARENT found in the URL?

2
Here was discussed and worked for me.Bogdan Alexandru Militaru

2 Answers

0
votes

When referencing drupal 7 uses nid for the reference. In your case you should use nid in the url or finding the nid from the parent alias. For the latter you can use drupal_get_normal_path() function which returns node/nid path and then extract the nid in your php filter like

$normalpath = drupal_get_normal_path($alias)
$parts=explode('/', $normalpath );          
$nid=$parts[1]; 
0
votes

Try with this code for

When the filter value IS in the URL or Default Provided:

$np = explode('/', drupal_get_normal_path($argument));
if (!empty($np[1])) {
 $handler->argument = $np[1];
 return TRUE;
} else {
 return FALSE;
}

Check this!