I have a field collection with two entity reference fields that I keep hidden on a node creation form. The reference fields in the hidden field collection are slowing down the page load time. I need to block the field collection from rendering at all. From what I understand it needs to happen before hook form alter. See Question - Does unset($form['field']); in hook_form_alter stop entity reference views select list queries from running?. Any help would really be appreciated!

  • The reference fields in the hidden field collection are slowing down the page load time I'm not sure why you'd think that is being caused by rendering? It'll be caused by the database queries (incessant joining). The only way to avoid those is to detach the field from whatever entity it's attached to. Field collection is known for its performance problems, I've yet to come across a use case where creating a custom compound field isn't more appropriate, and a lot faster
    – Clive
    Jan 17 '14 at 15:46
  • Thanks for the response Clive - I appreciate the help. I understand how the database queries are slowing things down. Is there any approach I can use to detach the field from the entity it's attached to before the node add form is built? The question I referenced suggests that queries might be stopped via hook_field_attach_form. Please excuse my ignorance - I am relatively new to programming.
    – Eazye1977
    Jan 17 '14 at 17:12
  • Sorry, by detach I meant actually remove the field from the entity altogether. There might be a simple hack but I don't know it - fields and entities are pretty configurable but I'm not sure where you'd hook into to stop a particular field from loading data in a particular context (either field_attach_form() or field_attach_load() in this case, probably the former but I'm not 100%)
    – Clive
    Jan 17 '14 at 17:54
  • I can think of one (rather nasty) hack actually...you could subclass FieldCollectionItemEntity and override the load/attach functions to exclude certain operations in certain contexts, then use hook_entity_info_alter() to update the entity class for the field_collection_item entity. As I say, rather nasty, but might be worth a look if you get desperate
    – Clive
    Jan 17 '14 at 18:01

In case this helps anyone - the hidden node reference fields that I have been using were having their lists of selectable nodes generated by views. I ended up using hook_views_query_alter to stop the view query from being run. Here's the code I put into my custom module:

 * Implements hook_views_query_alter().                                         
 * Disables node reference views. This drammatically  
 * speeds up performance.                                                       
 function mymodule_views_query_alter(&$view, &$query) {                         
  if ($view->name == "my_view") {                                               
    $view->executed = TRUE;                                                 
  if ($view->name == "my_view2") {                                               
    $view->executed = TRUE;                                                

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.