Currently, the share button is rendered via hook_ENTITY_view(), which limits its usage to entity view contexts only. This makes it difficult to reuse the button in other places like:
- Controllers and custom routes
- Custom blocks
- Headless/decoupled outputs
Developers have no clean way to render the button outside of entity templates.
Introduce a dedicated service, e.g. mobile_native_share.renderer, with a method like
public function render(?EntityInterface $entity = NULL): array;
This service would encapsulate the logic for generating the render array of the share button, using metadata from the passed entity (if any). It would:
- Extract url, title, and description from the entity or fallback to current request.
- Return a renderable array with the appropriate attributes and attached library.
- Be easily reusable in blocks, controllers, or Twig extensions.
The existing hook_ENTITY_view() implementation can then delegate to this service.
- Decouples rendering logic from entity view hooks.
- Enables reuse in any context (blocks, templates, custom routes).
- Makes the module more developer-friendly and testable.
- Opens the door for future enhancements (e.g. Twig function, JSON output for headless use).
Active
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.