field_ui_form_node_type_form_alter() shouldn't hack the form submit button

Created on 20 September 2016, about 9 years ago
Updated 18 August 2025, about 2 months ago

Field UI's alteration of the node type form causes problems for other modules that want to alter the same form:

function field_ui_form_node_type_form_alter(&$form, FormStateInterface $form_state) {
  // We want to display the button only on add page.
  if ($form_state->getFormObject()->getEntity()->isNew()) {
    $form['actions']['save_continue'] = $form['actions']['submit'];
    $form['actions']['save_continue']['#value'] = t('Save and manage fields');
    $form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] + 5;
    $form['actions']['save_continue']['#submit'][] = 'field_ui_form_node_type_form_submit';
    // Hide the 'Save content type' button.
    $form['actions']['submit']['#access'] = FALSE;
  }
}

- if your module's hook_form_alter() runs before this one, then you can add a submit handler in $form['actions']['submit'] as expected
- if your module's hook_form_alter() runs after this one, then attempting to do that will have no effect. You need to add it to $form['actions']['save_continue'] (and strictly speaking, check whether Field UI module is present!)

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

field_ui.module

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • πŸ‡¬πŸ‡§United Kingdom joachim

    This appears to no longer hide the button:

        if ($form_state->getFormObject()->getEntity()->isNew()) {
          $form['actions']['save_continue'] = $form['actions']['submit'];
          unset($form['actions']['submit']['#button_type']);
          $form['actions']['save_continue']['#value'] = $this->t('Save and manage fields');
          $form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] - 5;
          $form['actions']['save_continue']['#submit'][] = 'field_ui_form_manage_field_form_submit';
        }
    
Production build 0.71.5 2024