How to customize entity relationship titles and descriptions on create page?

Created on 6 April 2023, about 2 years ago
Updated 7 June 2023, almost 2 years ago

The default titles and descriptions on the /group/{id}/content/create page, and the titles on entity forms available from that page, are not user friendly depending on the purpose of the site and the user base. For example: "Add Group node (Article)" implies the user knows what a "Group" and a "node" is.

How can these be customized?

πŸ’¬ Support request
Status

Active

Version

3.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States aasarava San Diego

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aasarava
  • πŸ‡ΊπŸ‡ΈUnited States aasarava San Diego
  • πŸ‡ͺπŸ‡ΈSpain rteijeiro

    Same question here. I'm actually trying to change the name of the relationship which defaults to "content" and I'm not sure there is straightforward way to do it. Any hints?

  • πŸ‡ΊπŸ‡ΈUnited States aasarava San Diego

    This is as far as I got, which uses the human-readable content type labels instead of what the group module generates. Place this in a custom module and replace "my_module_" with your module name.

    I still don't know how to change the actual descriptions. If anyone can provide some guidance on further customizing this, that'd be greatly appreciated.

    /**
     * Implements hook_PLUGIN_ID_alter().
     */
    function my_module_group_relation_type_alter($definitions) {
      foreach ($definitions as &$definition) {
        // On the group/{id}/media/create and group/{id}/node/create pages,
        // that are generated by the Group module,
        // and on entity creation forms within groups,
        // use the plain human-readable bundle label (e.g., "Article", "Event").
        if ($definition->id() === 'group_node' || $definition->id() == 'group_media') {
          $entity_type = $definition->get('entity_type_id');
          $bundle = $definition->get('entity_bundle');
          $bundle_label = \Drupal::entityTypeManager()->getStorage($entity_type . '_type')->load($bundle)->label();
          $definition->set('label', new TranslatableMarkup('@bundle', ['@bundle' => $bundle_label]));
        }
      }
    }
    
Production build 0.71.5 2024