An invalid implementation mymodule_form_alter was added by hook_module_implements_alter I am trying to have my module alter menu_ui functions. Changing my module's weight didnt help and I read that hook_module_implements_alter is the way to go. So, as described here I am appending my module to the end of the implementations:

/**
 * Implements hook_module_implements_alter.
 */
function mymodule_module_implements_alter(&amp;$implementations, $hook) {
  if ('form_alter' == $hook) {
    $group = $implementations['mecca_hierarchy_access'];
    unset($implementations['mecca_hierarchy_access']);
    $implementations['mecca_hierarchy_access'] = $group;
  }
}


But this just throws:


  Uncaught PHP Exception RuntimeException: "An invalid implementation
  mymodule_form_alter was added by hook_module_implements_alter()" at
  /path/to/core/lib/Drupal/Core/Extension/ModuleHandler.php line 591


My form alter looks like this:

function mymodule_form_node_form_alter(&amp;$form, FormStateInterface $form_state) {
  // commented code
}


What do I do wrong?
The exception is raised from the following code. (See ModuleHandler::buildImplementationInfo().)

    // If a new implementation was added, verify that the function exists.
    if (!function_exists($module . '_' . $hook)) {
      throw new \RuntimeException("An invalid implementation {$module}_{$hook} was added by hook_module_implements_alter()");
    }


It simply happens because, in your case, there isn't any mecca_hierarchy_access_form_alter() or similar hook, most probably because there isn't any mecca_hierarchy_access module.

The code you want to use is probably the following one.

/**
 * Implements hook_module_implements_alter().
 */
function mymodule_module_implements_alter(&amp;$implementations, $hook) {
  if ('form_alter' == $hook &amp;&amp; isset($implementations['mymodule'])) {
    $group = $implementations['mymodule'];
    unset($implementations['mymodule']);
    $implementations['mymodule'] = $group;
  }
}


Always check the implementation of your module has not been already removed from another module, or your hook implementation would actually set $implementations['mymodule'] to NULL.