1

I'm trying to use the module ClosedQuestion together with EntityCache. When I enable EntityCache, then the fields on my CQ nodes becomes duplicated. I believe the cause is that both EntityCache, and ClosedQuestion, calls field_attach_load on the nodes.

There's a specific issue here, about this problem, but I'm looking for more general information, about what is the intended usage of field_attach_load? I've never seen a module doing it manually before, and don't think it's supposed to be used like this.

3
  • If you're looking for an example, I wrote a "casetracker" like module for D7 that added a Node's fields to the comment form. In that case, I also used field_attach_submit to save those fields too! It actually worked pretty well. here's the source Jan 24, 2012 at 16:09
  • Your using field_attach_form there, right? Still that's interesting, the use-cases should be similar. Your suggestion gave me the idea to grep for field_attach_load in other contrib modules. I only found it in media, which uses it to create dummy content during upgrade. While this doesn't really tell me anything definite, it certainly leans towards, "Using it for loading the node, is wrong".
    – Letharion
    Jan 25, 2012 at 12:05
  • Yes, sorry, sometimes you read what is familiar! I've never used form_attach_load, but it does indeed look similar. Jan 25, 2012 at 15:19

1 Answer 1

1

api.drupal.org says:

field_attach_load() is automatically called by the default entity controller class, and thus, in most cases, doesn't need to be explicitly called by the entity type module.

Basically only call it if you're implementing an entity type and don't want to use the default entity controller. I'm pretty sure ClosedQuestion is in the wrong, since it's only making a node type. All fields should be attached by the time hook_load() comes along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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