Loading auto_entity_form_mode.module +5 −3 Original line number Diff line number Diff line Loading @@ -13,18 +13,20 @@ function auto_entity_form_mode_entity_type_alter(array &$entity_types) { foreach ($entity_types as $entity_type_id => $entity_type) { // Get the form modes directly from config. We can't use the entity storage // since that would result in a recursive loop. $entity_form_mode_config_ids = $config_factory->listAll('core.entity_form_display.' . $entity_type_id); $entity_form_mode_config_ids = $config_factory->listAll('core.entity_form_mode.' . $entity_type_id); foreach ($entity_form_mode_config_ids as $entity_form_mode_config_id) { $entity_form_mode_config = $config_factory->get($entity_form_mode_config_id); $entity_form_mode_id = is_string($entity_form_mode_config->get('id')) ? (string) $entity_form_mode_config->get('id') : ''; [, $entity_form_mode_form_class_id] = explode('.', $entity_form_mode_id); // Do nothing when the form class is already registered. if ($entity_types[$entity_type_id]->hasHandlerClass('form', $entity_form_mode_config->get('mode'))) { if ($entity_types[$entity_type_id]->hasHandlerClass('form', $entity_form_mode_form_class_id)) { continue; } $default_entity_form_class = $entity_types[$entity_type_id]->getFormClass('default'); $entity_types[$entity_type_id]->setFormClass($entity_form_mode_config->get('mode'), $default_entity_form_class); $entity_types[$entity_type_id]->setFormClass($entity_form_mode_form_class_id, $default_entity_form_class); } } } tests/modules/auto_entity_form_mode_test/auto_entity_form_mode_test.info.yml 0 → 100644 +10 −0 Original line number Diff line number Diff line name: Auto entity form mode Test type: module description: 'Support module for Auto entity form mode tests' package: Testing dependencies: - auto_entity_form_mode:auto_entity_form_mode - drupal:node - drupal:taxonomy - drupal:user tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.node.my_custom_node_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - node id: node.my_custom_node_form_display label: My custom node form display targetEntityType: node cache: true tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.taxonomy_term.my_custom_taxonomy_term_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - taxonomy id: taxonomy_term.my_custom_taxonomy_term_form_display label: My custom taxonomy term form display targetEntityType: taxonomy_term cache: true tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.user.my_custom_user_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - user id: user.my_custom_user_form_display label: My custom user form display targetEntityType: user cache: true Loading
auto_entity_form_mode.module +5 −3 Original line number Diff line number Diff line Loading @@ -13,18 +13,20 @@ function auto_entity_form_mode_entity_type_alter(array &$entity_types) { foreach ($entity_types as $entity_type_id => $entity_type) { // Get the form modes directly from config. We can't use the entity storage // since that would result in a recursive loop. $entity_form_mode_config_ids = $config_factory->listAll('core.entity_form_display.' . $entity_type_id); $entity_form_mode_config_ids = $config_factory->listAll('core.entity_form_mode.' . $entity_type_id); foreach ($entity_form_mode_config_ids as $entity_form_mode_config_id) { $entity_form_mode_config = $config_factory->get($entity_form_mode_config_id); $entity_form_mode_id = is_string($entity_form_mode_config->get('id')) ? (string) $entity_form_mode_config->get('id') : ''; [, $entity_form_mode_form_class_id] = explode('.', $entity_form_mode_id); // Do nothing when the form class is already registered. if ($entity_types[$entity_type_id]->hasHandlerClass('form', $entity_form_mode_config->get('mode'))) { if ($entity_types[$entity_type_id]->hasHandlerClass('form', $entity_form_mode_form_class_id)) { continue; } $default_entity_form_class = $entity_types[$entity_type_id]->getFormClass('default'); $entity_types[$entity_type_id]->setFormClass($entity_form_mode_config->get('mode'), $default_entity_form_class); $entity_types[$entity_type_id]->setFormClass($entity_form_mode_form_class_id, $default_entity_form_class); } } }
tests/modules/auto_entity_form_mode_test/auto_entity_form_mode_test.info.yml 0 → 100644 +10 −0 Original line number Diff line number Diff line name: Auto entity form mode Test type: module description: 'Support module for Auto entity form mode tests' package: Testing dependencies: - auto_entity_form_mode:auto_entity_form_mode - drupal:node - drupal:taxonomy - drupal:user
tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.node.my_custom_node_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - node id: node.my_custom_node_form_display label: My custom node form display targetEntityType: node cache: true
tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.taxonomy_term.my_custom_taxonomy_term_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - taxonomy id: taxonomy_term.my_custom_taxonomy_term_form_display label: My custom taxonomy term form display targetEntityType: taxonomy_term cache: true
tests/modules/auto_entity_form_mode_test/config/install/core.entity_form_mode.user.my_custom_user_form_display.yml 0 → 100644 +9 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - user id: user.my_custom_user_form_display label: My custom user form display targetEntityType: user cache: true