Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this questionsee this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with Letharion's answer chosen by CommunityBot
re-wrote additional info
Source Link
Ashlar
  • 5.1k
  • 6
  • 35
  • 56

Two answers have addressed the process for applying the results of a view and placing it in another view as a contextual filter. But I still face the problem of having dozens of content types with at least a dozen view content pane variations in each. Instead of directly linking each view to the related facts, I will need to have the any of my view1 content views pass its results to a single, separate 'related fact' view.

CONTENT TYPE    SUB-CATEGORY       RELATED FACT (nid)
    Type 1 --------- General Info       101, 105 
                     Specifications     103, 105
                     Inspections        102 
                     Quality  
                     etc...   
   Type 2 ----------General Info       101, 106
                    Specifications     102, 103 
                    Cost factors       107
                    etc... 

Would this be performed through hook_views_post_execute? The apiView1 finds a specific content type and contains various sub-category articles sorted by the value in a subcategory field. In addition it contains a node reference shows an argument of '&$view' so I assumefield for related facts. View one filters for a content type and a subcategory and has exposed fields for display and a hidded field with thte related fact reference nodes.

View2 filters for 'related fact' articles and contains a contextual filter set for nid (please confirm/correct/clarify) I could definealthough the hooksetting applies to call the "related-facts" view using the $view->result.URL)

FinallyUsing the code in Letharion's answer, I need to display this 'related facts' content as a content pane directed to the proper locationforeach loop in my page display. In my case thisline 6 is compiling a panel layout and when the URl callslist of the correct patharticle ID's, not the view is displayed inrelated fact id's (the articles hold a reference to related facts, but the panel-page content panerelated facts do not have a node reference to articles). The 'related facts' will be displayed in another pane on I need to extract the pagerelated fact id's from the facts field in each node. I can placehave included the view for 'related facts'facts field in the correct location using Panels UIView1 definition, but it is not clear it will havecannot find the correct content called this way,result since the correct arguments are placed bycommand dpm($node); has been crashing and I don't know where the hook_views_post_execute fromvalues are stored in the main content viewarray. Is

Since there a waywill be more than one View1 cloned for different content types I thought it may make sense to use hook_views_post_execute and have coded it as follows:

function mymodule_views_post_execute (&$sourceview) {

  $nids = '';
  foreach($sourceview->result as $node) {
    $nids += $node->nid . ',';  //I need field name for $node->facts
    
  }
  
  $nids = rtrim($nids, ',');
  $view = views_get_view('get_related');
  
  //dpm($nids);  // Fatal error: Cannot unset string offsets...

  $view->execute_display('panel_pane_1', array($nids));
  }

Finally, I am not sure if I have to direct the hook_views_post_executedisplay of the view to be rendered in the desiredproper location or is this done simply by placing the related facts content pane? in the panel location through the Panels UI and let panels theming handle the rest.

Two answers have addressed the process for applying the results of a view and placing it in another view as a contextual filter. But I still face the problem of having dozens of content types with at least a dozen view content pane variations in each. Instead of directly linking each view to the related facts, I will need to have the any of my view1 content views pass its results to a single 'related fact' view.

Would this be performed through hook_views_post_execute? The api reference shows an argument of '&$view' so I assume (please confirm/correct/clarify) I could define the hook to call the "related-facts" view using the $view->result.

Finally, I need to display this 'related facts' content as a content pane directed to the proper location in my page display. In my case this is a panel layout and when the URl calls the correct path the view is displayed in the panel-page content pane. The 'related facts' will be displayed in another pane on the page. I can place the view for 'related facts' in the correct location using Panels UI, but it is not clear it will have the correct content called this way, since the correct arguments are placed by the hook_views_post_execute from the main content view. Is there a way to direct the hook_views_post_execute to be rendered in the desired content pane?

Two answers have addressed the process for applying the results of a view and placing it in another view as a contextual filter. But I still face the problem of having dozens of content types with at least a dozen view content pane variations in each. Instead of directly linking each view to the related facts, I will need to have the any of my view1 content views pass its results to a single, separate 'related fact' view.

CONTENT TYPE    SUB-CATEGORY       RELATED FACT (nid)
    Type 1 --------- General Info       101, 105 
                     Specifications     103, 105
                     Inspections        102 
                     Quality  
                     etc...   
   Type 2 ----------General Info       101, 106
                    Specifications     102, 103 
                    Cost factors       107
                    etc... 

View1 finds a specific content type and contains various sub-category articles sorted by the value in a subcategory field. In addition it contains a node reference field for related facts. View one filters for a content type and a subcategory and has exposed fields for display and a hidded field with thte related fact reference nodes.

View2 filters for 'related fact' articles and contains a contextual filter set for nid (although the setting applies to the URL)

Using the code in Letharion's answer, the foreach loop in line 6 is compiling a list of the article ID's, not the related fact id's (the articles hold a reference to related facts, but the related facts do not have a node reference to articles). I need to extract the related fact id's from the facts field in each node. I have included the facts field in the View1 definition, but cannot find the result since the command dpm($node); has been crashing and I don't know where the values are stored in the array.

Since there will be more than one View1 cloned for different content types I thought it may make sense to use hook_views_post_execute and have coded it as follows:

function mymodule_views_post_execute (&$sourceview) {

  $nids = '';
  foreach($sourceview->result as $node) {
    $nids += $node->nid . ',';  //I need field name for $node->facts
    
  }
  
  $nids = rtrim($nids, ',');
  $view = views_get_view('get_related');
  
  //dpm($nids);  // Fatal error: Cannot unset string offsets...

  $view->execute_display('panel_pane_1', array($nids));
  }

Finally, I am not sure if I have to direct the display of the view to the proper location or is this done simply by placing the related facts content pane in the panel location through the Panels UI and let panels theming handle the rest.

Added "Thus far" text
Source Link
Ashlar
  • 5.1k
  • 6
  • 35
  • 56

I am at the point in Drupal experience where I am attempting to solve site design challenges at the custom code level using Drupal and Views APIs. As usual, my apparently simple attempt to solve a problem has demonstrated to me how much I don't know yet!

I have a node-reference field that points to a 'related facts' content used by many different content types and subcategories for each of these types. While I can create a relationship and display the 'related facts' for a view, there are problems. For one, I want the related facts put in a separate block and to display a single list of related facts for the entire list of articles provided by the view. Views does not handle any duplicates for multiple nids with the same 'related facts' reference well. In addition, I would have to generate separate 'related facts' views for each content type and subcategory which will be quite a large number.

If I could create a separate related facts view that can accept a list of nids as an argument, the related facts view could be simplified. So my question is how to go about this. While it may be possible from within views, I am seeking a custom module php solution, so I need to achieve the following:

  1. Extract the results of any of the 'content type' views as a list of arguments. In addition to displaying the view results, I need to load the list of NIDs that are being displayed.

  2. Call the related facts view and pass the list of nids to it to use as a filter or contextual filter in the 'related facts' view.

Additional Information:

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

Thus Far:

Two answers have addressed the process for applying the results of a view and placing it in another view as a contextual filter. But I still face the problem of having dozens of content types with at least a dozen view content pane variations in each. Instead of directly linking each view to the related facts, I will need to have the any of my view1 content views pass its results to a single 'related fact' view.

Would this be performed through hook_views_post_execute? The api reference shows an argument of '&$view' so I assume (please confirm/correct/clarify) I could define the hook to call the "related-facts" view using the $view->result.

Finally, I need to display this 'related facts' content as a content pane directed to the proper location in my page display. In my case this is a panel layout and when the URl calls the correct path the view is displayed in the panel-page content pane. The 'related facts' will be displayed in another pane on the page. I can place the view for 'related facts' in the correct location using Panels UI, but it is not clear it will have the correct content called this way, since the correct arguments are placed by the hook_views_post_execute from the main content view. Is there a way to direct the hook_views_post_execute to be rendered in the desired content pane?

I am at the point in Drupal experience where I am attempting to solve site design challenges at the custom code level using Drupal and Views APIs. As usual, my apparently simple attempt to solve a problem has demonstrated to me how much I don't know yet!

I have a node-reference field that points to a 'related facts' content used by many different content types and subcategories for each of these types. While I can create a relationship and display the 'related facts' for a view, there are problems. For one, I want the related facts put in a separate block and to display a single list of related facts for the entire list of articles provided by the view. Views does not handle any duplicates for multiple nids with the same 'related facts' reference well. In addition, I would have to generate separate 'related facts' views for each content type and subcategory which will be quite a large number.

If I could create a separate related facts view that can accept a list of nids as an argument, the related facts view could be simplified. So my question is how to go about this. While it may be possible from within views, I am seeking a custom module php solution, so I need to achieve the following:

  1. Extract the results of any of the 'content type' views as a list of arguments. In addition to displaying the view results, I need to load the list of NIDs that are being displayed.

  2. Call the related facts view and pass the list of nids to it to use as a filter or contextual filter in the 'related facts' view.

Additional Information:

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

I am at the point in Drupal experience where I am attempting to solve site design challenges at the custom code level using Drupal and Views APIs. As usual, my apparently simple attempt to solve a problem has demonstrated to me how much I don't know yet!

I have a node-reference field that points to a 'related facts' content used by many different content types and subcategories for each of these types. While I can create a relationship and display the 'related facts' for a view, there are problems. For one, I want the related facts put in a separate block and to display a single list of related facts for the entire list of articles provided by the view. Views does not handle any duplicates for multiple nids with the same 'related facts' reference well. In addition, I would have to generate separate 'related facts' views for each content type and subcategory which will be quite a large number.

If I could create a separate related facts view that can accept a list of nids as an argument, the related facts view could be simplified. So my question is how to go about this. While it may be possible from within views, I am seeking a custom module php solution, so I need to achieve the following:

  1. Extract the results of any of the 'content type' views as a list of arguments. In addition to displaying the view results, I need to load the list of NIDs that are being displayed.

  2. Call the related facts view and pass the list of nids to it to use as a filter or contextual filter in the 'related facts' view.

Additional Information:

Using this strategy I began by defining a view and attempting to extract the results from it. This attempt led to a problem finding the results in the view object (see this question). Once I get the results I will need to generate another view that has those results as filters. I have seen views implemented from code as include files where all the parameters are coded, but have not found examples that define and generate a view and manipulate the results using a php function. Any examples or links would be appreciated.

Thus Far:

Two answers have addressed the process for applying the results of a view and placing it in another view as a contextual filter. But I still face the problem of having dozens of content types with at least a dozen view content pane variations in each. Instead of directly linking each view to the related facts, I will need to have the any of my view1 content views pass its results to a single 'related fact' view.

Would this be performed through hook_views_post_execute? The api reference shows an argument of '&$view' so I assume (please confirm/correct/clarify) I could define the hook to call the "related-facts" view using the $view->result.

Finally, I need to display this 'related facts' content as a content pane directed to the proper location in my page display. In my case this is a panel layout and when the URl calls the correct path the view is displayed in the panel-page content pane. The 'related facts' will be displayed in another pane on the page. I can place the view for 'related facts' in the correct location using Panels UI, but it is not clear it will have the correct content called this way, since the correct arguments are placed by the hook_views_post_execute from the main content view. Is there a way to direct the hook_views_post_execute to be rendered in the desired content pane?

clarified I am seeking a solution using php.
Source Link
Ashlar
  • 5.1k
  • 6
  • 35
  • 56
Loading
Tweeted twitter.com/#!/StackDrupal/status/208743641114607616
Notice added Authoritative reference needed by Ashlar
Bounty Started worth 100 reputation by Ashlar
added 7 characters in body
Source Link
Ashlar
  • 5.1k
  • 6
  • 35
  • 56
Loading
Source Link
Ashlar
  • 5.1k
  • 6
  • 35
  • 56
Loading