Change record status: 
Project: 
Introduced in branch: 
8.x
Introduced in version: 
8.0
Description: 

Content entities had a links list in their annotations, so you can specify different URLs for different use cases. This has now been extended to configuration entities as well, so instead of specifying a uri() method or a url_callback annotation specifying a function, you can easily specify the (admin) URL for configuration entities in annotations.

The URL should be in the form of a router path (e.g. custom_block.type_edit).

Before:

class CustomBlockType extends ConfigEntityBase {
 
  // ....

  /**
   * Overrides \Drupal\Core\Entity\Entity::uri().
   */
  public function uri() {
    return array(
      'path' => 'admin/structure/block/custom-blocks/manage/' . $this->id(),
      'options' => array(
        'entity_type' => $this->entityType,
        'entity' => $this,
      )
    );
  }

  // ....

}

After:

/**
 * Defines the custom block type entity.
 *
 * @EntityType(
 *   id = "custom_block_type",
 *   // ...........
 *   links = {
 *     "edit-form" = "custom_block.type_edit"
 *   }
 * )
 */
class CustomBlockType extends ConfigEntityBase {
 // ....
}

So far only the edit-form URI pattern is supported and it should be used the same way as with content entities. Provide the router callback here.

If you need to dynamically generate the URI for your entity, it is still perfectly possible to define the uri() method and do your own logic. An example for that is FieldInstance::uri() which generate the URI based on entity base URLs: https://api.drupal.org/api/drupal/core%21modules%21field%21lib%21Drupal%...

However if your URI follows a simple pattern anyway, you can just use the annotation and avoid copy-pasting all that code.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done