0

I've manipulated the edit node form via hook_form_BASE_FORM_ID_alter() to insert a select pull-down menu.

In my module, I've implemented hook_entity_update() to fire when the edit node form is submitted. How do you get the form_state in hook_entity_update()? I want to save the user's choice from the select pull-down.

1 Answer 1

2

$form_state is not available there.

You might want to consider using fields and widgets, then you get a lot for free.

If that's not an option then you can register a so called #entity_builder:

function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_state) {
  // ...
  $form['#entity_builders'][] = 'menu_ui_form_node_type_form_builder';
}

function menu_ui_form_node_type_form_builder($entity_type, NodeTypeInterface $type, &$form, FormStateInterface $form_state) {
  $type->setThirdPartySetting('menu_ui', 'available_menus', array_values(array_filter($form_state->getValue('menu_options'))));
  $type->setThirdPartySetting('menu_ui', 'parent', $form_state->getValue('menu_parent'));
}

The example is for the node type config entity, but it should work pretty much the same way for a content entity. book_form_node_form_alter() is an example for nodes.

1
  • Thanks for your answer. I've set up some code similar to what you described found in Drupal 8 core->menu_ui.module. If I understand it correctly, you insert a 'submit' type in the associative array and point it to a function that will have the form_state object. Thanks again.
    – jbhovik
    Jun 30, 2015 at 21:37

Your Answer

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

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