For the D8 version of the automatic entity labels module, I am trying to create a list of entity label properties and their visibility on forms (as configured via the form display configuration system); and if they have a page for configuring the form display of a property, I would like to link back to the respective configuration page.
Unfortunately there does not seem to be an API function for figuring out the respective routes and parameters for a given $entity_type
, $bundle
and (form) $mode
; therefore I am currently using the following piece of code:
function getFormDisplayConfigurationRoute(EntityTypeInterface $entity_type, $bundle, $mode = 'default') {
$route = NULL;
// Routes are only built for fieldable entity types which have an
// 'admin-form' link template.
if ($entity_type->isFieldable() && $entity_type->hasLinkTemplate('admin-form')) {
if ($mode == 'default') {
$route = array(
'route_name' => 'field_ui.form_display_overview_' . $entity_type->id(),
'route_parameters' => array($entity_type->getBundleEntityType() => $bundle),
'route_options' => array(),
);
}
else {
$route = array(
'route_name' => 'field_ui.form_display_overview_form_mode_' . $entity_type->id(),
'route_parameters' => array(
$entity_type->getBundleEntityType() => $bundle,
'form_mode_name' => $mode
),
'route_options' => array(),
);
}
}
return $route;
}
I'm wondering whether there is an easier way to do this; e.g. as a module developer I feel that I shouldn't really need to know that form display configuration routes are only built for fieldable entity types which have an 'admin-form' link template; neither the fact that there are different routes for the 'default' vs. additional form modes.
Is there currently a better way to do this? If not, could the logic above be added into maybe EntityFormDisplay or EntityDisplayBase?
Comment | File | Size | Author |
---|---|---|---|
#2 | form-mode-route.png | 8.94 KB | bforchhammer |
#2 | overview-route.png | 8.54 KB | bforchhammer |
Comments
Comment #1
tim.plunkettActually, the
else
case can also handle the 'default' mode, the field_ui.form_display_overview_ part is just a nice to have.This is in field_ui, which is a completely optional module. That is why this isn't codified into the entity types themselves.
I think that loop isn't too much to ask if you remove the duplication.
Also, a side note, but you should probably use \Drupal\Core\Url instead of an array.
Comment #2
bforchhammer CreditAttribution: bforchhammer commentedYes it works, but there is a subtle difference in how local tasks and breadcrumbs are rendered for the 'default' mode depending on the route.
Route
form_display_overview_{type}
:admin/structure/types/manage/article/form-display
Route
form_display_overview_form_mode_{type}
:admin/structure/types/manage/article/form-display/default
I'm not sure whether that's a bug or intended because it is actually different paths?
Yes, that makes sense! Still learning, thanks. :)
Comment #13
cilefen CreditAttribution: cilefen commentedI am closing this support request because there have been no recent comments.