Skip to content

Fixes annotations for gesso link field formatters#1002

Open
tomealter wants to merge 1 commit into5.xfrom
gesso-helper-annotations
Open

Fixes annotations for gesso link field formatters#1002
tomealter wants to merge 1 commit into5.xfrom
gesso-helper-annotations

Conversation

@tomealter
Copy link
Copy Markdown
Contributor

Discovered this issue when attempting to render a link field using the gesso button field formatter and found that nothing was being rendered on the front end.

Drupal’s real render element annotation is @RenderElement from Drupal\Core\Render\Annotation\RenderElement. So from Drupal’s perspective, @RenderElementBase("gesso_button") is just a docblock comment, not a real plugin definition.

This PR was created in conjunction with the PR made to gesso-uswds here

@tomealter tomealter requested a review from coreylafferty March 3, 2026 19:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

The pull request updates annotations in three render element classes located in gesso_helper/src/Element/. For GessoButton, GessoIcon, and GessoIconLink, the @RenderElementBase annotation in docblocks is replaced with @RenderElement. The GessoIcon and GessoIconLink files also include new imports for RenderElement from Drupal\Core\Render\Element. All class signatures remain unchanged, and the classes continue to extend RenderElementBase. These are metadata-level changes that alter how Drupal identifies the render element implementations.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and refers to 'gesso link field formatters' but the actual changes affect GessoButton, GessoIcon, and GessoIconLink render elements, not specifically link field formatters. Consider clarifying the title to 'Fix render element annotations for Gesso components' or 'Fix @RenderElement annotations in Gesso render elements' for better accuracy.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description is related to the changeset, explaining the motivation (broken rendering) and the fix (correcting annotations from @RenderElementBase to @RenderElement).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gesso-helper-annotations

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
gesso_helper/src/Element/GessoButton.php (1)

8-37: ⚠️ Potential issue | 🔴 Critical

Import @RenderElement annotation from the correct namespace.

The @RenderElement annotation must be imported from Drupal\Core\Render\Annotation, not Drupal\Core\Render\Element. Without the correct annotation class, plugin discovery will fail.

Suggested fix
-use Drupal\Core\Render\Element\RenderElement;
+use Drupal\Core\Render\Annotation\RenderElement;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gesso_helper/src/Element/GessoButton.php` around lines 8 - 37, The
`@RenderElement` annotation is imported from the wrong namespace; replace the
incorrect import (RenderElement from Drupal\Core\Render\Element) with the
annotation class from Drupal\Core\Render\Annotation so the class-level
`@RenderElement`("gesso_button") annotation resolves correctly—update the use
statement in GessoButton.php to import RenderElement from
Drupal\Core\Render\Annotation and remove the old Element import so plugin
discovery works.
gesso_helper/src/Element/GessoIconLink.php (1)

8-37: ⚠️ Potential issue | 🟡 Minor

Use the correct annotation namespace in the import.

Line 8 imports Drupal\Core\Render\Element\RenderElement, but the correct class for the @RenderElement annotation is Drupal\Core\Render\Annotation\RenderElement. Update the import for consistency with Drupal's plugin annotation conventions. Note: GessoButton.php and GessoIcon.php have the same incorrect import and should also be corrected.

Suggested fix
-use Drupal\Core\Render\Element\RenderElement;
+use Drupal\Core\Render\Annotation\RenderElement;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gesso_helper/src/Element/GessoIconLink.php` around lines 8 - 37, The class
uses the wrong import for the RenderElement annotation: replace the current use
statement for Drupal\Core\Render\Element\RenderElement with the annotation class
use Drupal\Core\Render\Annotation\RenderElement so the
`@RenderElement`("gesso_icon_link") annotation resolves correctly; update the use
line in GessoIconLink (and apply the same change to GessoButton and GessoIcon
where they import the Element namespace) to import
Drupal\Core\Render\Annotation\RenderElement instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@gesso_helper/src/Element/GessoIcon.php`:
- Around line 6-11: The import at the top of GessoIcon.php is wrong for the
annotation: replace the current import of
Drupal\Core\Render\Element\RenderElement with the annotation class
Drupal\Core\Render\Annotation\RenderElement so the `@RenderElement`("gesso_icon")
annotation on the GessoIcon class is discoverable and the render element
registers correctly; update the use statement in GessoIcon.php accordingly and
keep the existing `@RenderElement` annotation intact.

---

Outside diff comments:
In `@gesso_helper/src/Element/GessoButton.php`:
- Around line 8-37: The `@RenderElement` annotation is imported from the wrong
namespace; replace the incorrect import (RenderElement from
Drupal\Core\Render\Element) with the annotation class from
Drupal\Core\Render\Annotation so the class-level `@RenderElement`("gesso_button")
annotation resolves correctly—update the use statement in GessoButton.php to
import RenderElement from Drupal\Core\Render\Annotation and remove the old
Element import so plugin discovery works.

In `@gesso_helper/src/Element/GessoIconLink.php`:
- Around line 8-37: The class uses the wrong import for the RenderElement
annotation: replace the current use statement for
Drupal\Core\Render\Element\RenderElement with the annotation class use
Drupal\Core\Render\Annotation\RenderElement so the
`@RenderElement`("gesso_icon_link") annotation resolves correctly; update the use
line in GessoIconLink (and apply the same change to GessoButton and GessoIcon
where they import the Element namespace) to import
Drupal\Core\Render\Annotation\RenderElement instead.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a8bb2b2 and 54c9577.

📒 Files selected for processing (3)
  • gesso_helper/src/Element/GessoButton.php
  • gesso_helper/src/Element/GessoIcon.php
  • gesso_helper/src/Element/GessoIconLink.php

Comment on lines +6 to +11
use Drupal\Core\Render\Element\RenderElement;

/**
* Provides an SVG icon element.
*
* @RenderElementBase("gesso_icon")
* @RenderElement("gesso_icon")
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "GessoIcon.php" -type f

Repository: forumone/gesso

Length of output: 98


🏁 Script executed:

fd -t f "GessoIcon.php" | head -20

Repository: forumone/gesso

Length of output: 96


🌐 Web query:

Drupal RenderElement annotation class name Drupal 10 11

💡 Result:

In Drupal 10 and Drupal 11, the render-element plugin annotation class is:

  • \Drupal\Core\Render\Annotation\RenderElement (used as @RenderElement("my_element")) [1], [2]

However, in Drupal 10.3+ and Drupal 11, core render/form elements are also (and increasingly) defined using PHP attributes:

  • \Drupal\Core\Render\Attribute\RenderElement (and for form elements: \Drupal\Core\Render\Attribute\FormElement) [3]

Sources:
[1] Drupal API: Annotation group lists RenderElement and its file core/lib/Drupal/Core/Render/Annotation/RenderElement.php
[2] Drupal API: Example showing @RenderElement("view")
[3] Drupal API “Form and render elements” list showing \Drupal\Core\Render\Attribute\RenderElement / \Drupal\Core\Render\Attribute\FormElement


🏁 Script executed:

cat -n gesso_helper/src/Element/GessoIcon.php

Repository: forumone/gesso

Length of output: 1790


Import the annotation class, not the element base class.

Line 6 imports Drupal\Core\Render\Element\RenderElement, but the @RenderElement annotation requires Drupal\Core\Render\Annotation\RenderElement. The current import prevents proper annotation discovery, causing the gesso_icon render element to fail registration.

Suggested fix
-use Drupal\Core\Render\Element\RenderElement;
+use Drupal\Core\Render\Annotation\RenderElement;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use Drupal\Core\Render\Element\RenderElement;
/**
* Provides an SVG icon element.
*
* @RenderElementBase("gesso_icon")
* @RenderElement("gesso_icon")
use Drupal\Core\Render\Annotation\RenderElement;
/**
* Provides an SVG icon element.
*
* `@RenderElement`("gesso_icon")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@gesso_helper/src/Element/GessoIcon.php` around lines 6 - 11, The import at
the top of GessoIcon.php is wrong for the annotation: replace the current import
of Drupal\Core\Render\Element\RenderElement with the annotation class
Drupal\Core\Render\Annotation\RenderElement so the `@RenderElement`("gesso_icon")
annotation on the GessoIcon class is discoverable and the render element
registers correctly; update the use statement in GessoIcon.php accordingly and
keep the existing `@RenderElement` annotation intact.

@coreylafferty coreylafferty self-requested a review March 5, 2026 21:07
@forumone forumone deleted a comment from coderabbitai Bot Mar 5, 2026
Copy link
Copy Markdown
Member

@dcmouyard dcmouyard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the unnecessary use statements for Classes we don’t use.

namespace Drupal\gesso_helper\Element;

use Drupal\Core\Render\Element\RenderElementBase;
use Drupal\Core\Render\Element\RenderElement;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t need this line since we never use RenderElement in this file and Drupal automatically imports annotation classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants