2

The site I am building is for a parts database and parts are related to each other - eg a circuit board can have a bunch of screws and relays that are sub parts and the board itself can be a sub-part of a module.

When you are registering a circuit board (node-add) you don't need to associate it with parent parts or sub parts. But you may want to do that when you edit it (node-edit).

The parts are associated by entity reference fields and the entity select views take a bit of time to load. I want to save that load time for the node-add by excluding those fields from the node-add form completely (not just hiding them) but I want them to load as normal for the node-edit form.

Thanks very much and have a great Friday!

-1

Okay I got it to work. On new nodes there is no NID on existing nodes there is. This code works.

function custom_form_alter(&$form, $form_state, $form_id) {
if($form_id == 'custom_node_form') {
    if (empty($form['nid']['#value'])) {
    unset($form['field_remove_this_field_name']);
    }

}

Unfortunately I still have a slow load time and I suspect that even though I'm unsetting the form fields that involve entity references (and therefore views queries to populate selection lists) that the queries are still getting run.

It's only really slow on the first form load after clearing caches. The second form load is much faster.

If anyone has any ideas to speed up the initial form load, I'd love to hear them.

It may be that I need to create a custom form from scratch using module code and only load the essential fields.

1
  • 1
    this is not a good option, use "unset" is a very bad idea, taking in mind that other modules can use form_alter with those fields and that will give php notices. use the #access property instead
    – svelandiag
    Sep 16 '14 at 4:32

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.