Problem/Motivation

When creating a group, the title of the page is "Add group", regardless of what type of group you are adding.

The node module displays "Create @name" (where @name is the bundle label). It does so by adding a _title_callback for the node.add route (defined in core/modules/node/node.routing.yml); which it sets to \Drupal\node\Controller\NodeController::addPageTitle, which looks like:

public function addPageTitle(NodeTypeInterface $node_type) {
  return $this->t('Create @name', ['@name' => $node_type->label()]);
}

Steps to reproduce

  1. Set up a new Drupal 8.5 site using the standard install profile.
  2. Clone the group module (I'm at commit 674ba8a, the HEAD of 8.x-1.x at the time of writing)
  3. Enable the group module
  4. Create one group type from /admin/group/types/add. I made a type with the name "Lorem"
  5. Try to add a group of that type from /group/add.
    • Expected behavior: the page title says "Add Lorem"
    • Actual behavior: the page title says "Add group"

Proposed resolution

Do the same thing that the Node module does. That is to say:

  1. Add a \Drupal\group\Entity\Controller\GroupController::addPageTitle
  2. Set the route to reference it via a _title_callback

Note that, unlike the Node module, the route is defined in \Drupal\group\Entity\Routing\GroupRouteProvider::getAddFormRoute so we'll have to add the _title_callback in there.

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit

User interface changes

When adding a new group, the bundle label is displayed as the title of the group/add form.

API changes

None.

Data model changes

None.

Comments

mparker17 created an issue. See original summary.

mparker17’s picture

Title: Display "Create @bundle_label" instead of "Add group" when adding a group » Display "Add @bundle_label" instead of "Add group" when adding a group when only one group type
Issue summary: View changes
StatusFileSize
new28.84 KB
new32.46 KB
new32.6 KB

After a bit of investigation, this only happens if you have one group type: updated issue title and summary.

Also, uploaded some screenshots comparing the behavior when there is one group type vs two group types.

I also uploaded a screenshot showing what the Node module does when there's only one node type for comparison (and as an example of the desired behavior).

mparker17’s picture

Assigned: mparker17 » Unassigned
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.76 KB
new26.93 KB

Here's a patch that fixes the issue; and a screenshot showing the change.

Status: Needs review » Needs work

The last submitted patch, 3: 2989280-3-display-add-bundle-label.patch, failed testing. View results

mparker17’s picture

With an error like:

Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization.
This import does not contain system.site configuration, so has been rejected.

... I think Testbot is having a bad day?

lolcode’s picture

Status: Needs work » Reviewed & tested by the community

This worked for me and the code looks fine as far as I can tell.

kristiaanvandeneynde’s picture

It overwrites this part of EntityController:


  /**
   * Provides a generic add title callback for entities with bundles.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   * @param string $entity_type_id
   *   The entity type ID.
   * @param string $bundle_parameter
   *   The name of the route parameter that holds the bundle.
   *
   * @return string
   *   The title for the entity add page, if the bundle was found.
   */
  public function addBundleTitle(RouteMatchInterface $route_match, $entity_type_id, $bundle_parameter) {
    $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
    // If the entity has bundle entities, the parameter might have been upcasted
    // so fetch the raw parameter.
    $bundle = $route_match->getRawParameter($bundle_parameter);
    if ((count($bundles) > 1) && isset($bundles[$bundle])) {
      return $this->t('Add @bundle', ['@bundle' => $bundles[$bundle]['label']]);
    }
    // If the entity supports bundles generally, but only has a single bundle,
    // the bundle is probably something like 'Default' so that it preferable to
    // use the entity type label.
    else {
      return $this->addTitle($entity_type_id);
    }
  }

But given how group doesn't ship with default group types... sure, why the hell not.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Fixed
mparker17’s picture

Issue summary: View changes

Awesome, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.