Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created July 7, 2018 11:56
Show Gist options
  • Select an option

  • Save cyberlex404/6ed1269321da85a4d4404d95ffd34f47 to your computer and use it in GitHub Desktop.

Select an option

Save cyberlex404/6ed1269321da85a4d4404d95ffd34f47 to your computer and use it in GitHub Desktop.
function housing_entity_type_alter(array &$entity_types) {
$form_modes = \Drupal::service('entity_display.repository')->getAllFormModes();
foreach ($form_modes as $entity_type => $display_modes) {
if ($entity_type !== 'housing') {
// We are only interested in adding a handler to the Node entity.
continue;
}
/* @var \Drupal\Core\Entity\EntityTypeInterface $entity */
$entity = $entity_types[$entity_type];
foreach ($display_modes as $machine_name => $form_display) {
if ($machine_name != 'register') {
// Get the correct canonical path to add operation.
$path = $entity->getLinkTemplate('canonical') . "/$machine_name";
$default_handler_class = $entity->getHandlerClasses()['form']['default'];
$entity->setFormClass($machine_name, $default_handler_class)
->setLinkTemplate($machine_name, $path);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment