How can I setup automatic subpages for existing pages using a view with a contextual filter that uses the URL to determine the filter value? I have two content types that are being linked via entity references.

Area of Expertise [Existing URL: /expertise/specific-area-here]
Employee [Desired URL: /expertise/specific-area-here/staff/specific-employee-here]

Employee has an entity reference field that contains all of the areas of expertise and only one value is allowed to be selected.
For example:
I have an area of expertise called &quot;Pathology&quot; and an employee named &quot;John Doe&quot;. In John Doe, I select that the area of expertise is &quot;Pathology&quot;.
When I'm on the area of expertise page for a particular area of expertise, I am showing all of the employees that specialize in that area of expertise in the sidebar second region. To do that I'm using a view that generates a block. Within the view I have a contextual filter using the following chunk of PHP code to provide the default filter value:
$filterValue = -1;

$node = menu_get_object();

if(!empty($node))
{
    switch($node-&gt;type)
    {
        case 'area_of_expertise':
            $filterValue = $node-&gt;nid;
            break;
    }
}

return $filterValue;

All of that is working properly.
What I want to do now is have a staff page that shows all of the staff associated with a particular area of expertise. I want the URL to be /expertise/specific-area-here/staff.
For example, if I want to see all of the staff that are associated with the area of expertise called &quot;Pathology&quot; (located at /expertise/pathology) then I would want the staff page to be available at /expertise/pathology/staff.
The issue I'm having is figuring out how to set up the contextual filter such that the &quot;/expertise/pathology&quot; piece of the URL of /expertise/pathology/staff can be processed so that Drupal knows which area of expertise to use to filter.
Also, the breadcrumbs should work as follows:
If I'm on the Pathology area of expertise page, the breadcrumbs should show:
Home &gt; Pathology

If I'm on the Pathology staff page, the breadcrumbs should show:
Home &gt; Pathology &gt; Staff

If I've drilled down into John Doe's page, the breadcrumbs should show:
Home &gt; Pathology &gt; Staff &gt; John Doe

How should I setup the contextual filter to allow this behavior and how should I configure the &quot;Path&quot; under &quot;Page Settings&quot; in the view?
After much trial and error, I found a solution that seems to work for me.

The first thing I had to do was switch from using a "provide default filter value" to specifying custom validation criteria via PHP:

$normalPath = drupal_get_normal_path('expertise/' . $argument);
$urlPieces = explode('/', $normalPath);

if(!isset($urlPieces[1]))
{
    return false;
}

$nodeId = $urlPieces[1];
$node = node_load($nodeId);

if(!empty($node))
{
    switch($node-&gt;type)
    {
        case 'area_of_expertise':
            $handler-&gt;argument = $node-&gt;nid;
            return true;
    }
}

return false;


Thanks to Cameron for the bits about $argument and $handler-&gt;argument.

Once I figured out how to use argument to generate the URL which then allowed me to look-up the node ID, I was able to reuse most of the code that I had before in the "Provide Default Value" section.

The next issue was the breadcrumbs. Before I did anything extra, the breadcrumbs were showing as Home &gt;   &gt; Staff. I ended up having to create a new menu item called Staff in the main menu that was a child of Pathology. So then the breadcrumbs showed as Home &gt; Pathology &gt; Staff &gt; Staff which is still not what I wanted.

I found out that views likes to add each contextual filter as a breadcrumb so that you can navigate up and get less and less granular. Normally this would be a nice feature, but I couldn't see any way to turn it off.

So I found a post that detailed how to remove the breadcrumbs which I tried to implement via hook_preprocess_page. This ended up not affecting the breadcrumbs at all because the views module was altering the breadcrumbs after that hook was being run.

Then I found another post that detailed how to affect the breadcrumbs after the view was ready to be rendered using hook_views_pre_render.

So I have the following code as my hook:

function MODULE_views_pre_render(&amp;$vars)
{
    $page = menu_get_item();

    if(($page['page_callback'] == 'views_page') &amp;&amp; ($page['page_arguments'][0] == 'staff_cross_reference'))
    {
        $breadcrumbs = drupal_get_breadcrumb();
        array_pop($breadcrumbs);
        drupal_set_breadcrumb($breadcrumbs);
    }
}


And now my breadcrumbs look like Home &gt; Pathology &gt; Staff which is exactly what I want!