1

I'm trying to alter an entity form handler. The method EntityType::setHandlerClass() allows for the 'form' handler to be set, but this value is an array, and I only want to override a single item of the array.

The entity handlers definition:

handlers = {
    "storage" = "Drupal\user\UserStorage",
    "storage_schema" = "Drupal\user\UserStorageSchema",
    "access" = "Drupal\user\UserAccessControlHandler",
    "list_builder" = "Drupal\user\UserListBuilder",
    "views_data" = "Drupal\user\UserViewsData",
    "route_provider" = {
      "html" = "Drupal\user\Entity\UserRouteProvider",
    },
    "form" = {
      "default" = "Drupal\user\ProfileForm",
      "cancel" = "Drupal\user\Form\UserCancelForm",
      "register" = "Drupal\user\RegisterForm"
    },
    "translation" = "Drupal\user\ProfileTranslationHandler"
  }

I'm trying to figure out how to override the form.register handler, but as the first argument to setEntityHandler() is a string, I cannot figure out how to set a nested value.

1 Answer 1

1

I have found the solution. Instead of using EntityType::setHandlerClass(), use EntityType::setFormClass().

2
  • 1
    Curious to know, where did you put this code inside of?
    – No Sssweat
    Feb 16, 2020 at 16:22
  • 1
    hook_entity_type_alter()
    – Jaypan
    Feb 16, 2020 at 16:49

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.