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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Actually, 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.

bforchhammer’s picture

FileSize
8.54 KB
8.94 KB

Actually, the else case can also handle the 'default' mode, the field_ui.form_display_overview_ part is just a nice to have.

Yes 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?

Also, a side note, but you should probably use \Drupal\Core\Url instead of an array.

Yes, that makes sense! Still learning, thanks. :)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
cilefen’s picture

Status: Active » Closed (outdated)
Issue tags: -entity, -Entity Field API, -form display

I am closing this support request because there have been no recent comments.