drupal-eca-recipe/eca_lib_0039

Add an edit icon to node titles in teasers

Maintainers

Package info

gitlab.lakedrops.com/drupal/recipes/eca_lib_0039/

Type:drupal-recipe

pkg:composer/drupal-eca-recipe/eca_lib_0039

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

1.1.1 2026-08-23 15:32 UTC

This package is auto-updated.

Last update: 2026-08-23 15:32:54 UTC


README

ID: eca_lib_0039

Editors maintain a lot of content through teaser lists. This model puts the edit screen one click away: whenever a node is rendered in the teaser view mode, an edit link is added to the rendered output for users who are allowed to edit that node. The link points to the node's edit form.

How it works

  1. The eca_render:entity event fires whenever a node is rendered, and provides the render array and the active view mode.
  2. A scalar condition checks that [event:mode] equals teaser. Every other view mode stops the model here, so full pages, search results and entity references render unchanged.
  3. The eca_render_cacheability action adds the user.permissions cache context. This runs before the access check, so both outcomes — link and no link — are cached against the same context.
  4. An access condition (eca_entity_is_accessible, update) lets only users who may actually edit the node through to the final step.
  5. The eca_render_link action adds the link, using [node:edit-url] for the target and Edit [node:title] as the link text.

Points worth copying

  • The render event fires for every node on the site, so the view-mode condition is what keeps the change teaser-only.
  • Anything user-dependent in a render array needs cache metadata. Node teasers are render-cached, so without the user.permissions cache context the first variant rendered would be served to everyone — an editor's link shown to anonymous visitors, or editors never seeing it at all.
  • Add the cache context before the access check, not inside the allowed branch, so the negative outcome carries it too.
  • Access is checked explicitly. A render-time addition does not inherit any access check, so without the condition every visitor would see a link that returns 403 when followed.
  • The link text is Edit [node:title] rather than an icon, so it has an accessible name that says which node it edits.
  • The model only alters the in-memory render array, so no node is ever saved and the model cannot recurse.

Requirements

This recipe installs the eca, eca_base, eca_content, eca_render and modeler_api modules. It works with any node content type and needs no particular field.

Note that the link is added as its own element in the rendered teaser, next to the title rather than inside the title's own link — nesting a link inside the title's <a> would produce invalid markup.

Installation

## Import recipe
composer require drupal-eca-recipe/eca_lib_0039

# Apply recipe with Drush (requires version 13 or later):
drush recipe ../recipes/eca_lib_0039

# Apply recipe without Drush:
cd web && php core/scripts/drupal recipe ../recipes/eca_lib_0039

# Rebuilding caches is optional, sometimes required:
drush cr