Fixes annotations for gesso link field formatters#1002
Conversation
📝 WalkthroughWalkthroughThe pull request updates annotations in three render element classes located in gesso_helper/src/Element/. For GessoButton, GessoIcon, and GessoIconLink, the 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
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 | 🔴 CriticalImport
@RenderElementannotation from the correct namespace.The
@RenderElementannotation must be imported fromDrupal\Core\Render\Annotation, notDrupal\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 | 🟡 MinorUse the correct annotation namespace in the import.
Line 8 imports
Drupal\Core\Render\Element\RenderElement, but the correct class for the@RenderElementannotation isDrupal\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.
📒 Files selected for processing (3)
gesso_helper/src/Element/GessoButton.phpgesso_helper/src/Element/GessoIcon.phpgesso_helper/src/Element/GessoIconLink.php
| use Drupal\Core\Render\Element\RenderElement; | ||
|
|
||
| /** | ||
| * Provides an SVG icon element. | ||
| * | ||
| * @RenderElementBase("gesso_icon") | ||
| * @RenderElement("gesso_icon") |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "GessoIcon.php" -type fRepository: forumone/gesso
Length of output: 98
🏁 Script executed:
fd -t f "GessoIcon.php" | head -20Repository: 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.phpRepository: 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.
| 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.
dcmouyard
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
We don’t need this line since we never use RenderElement in this file and Drupal automatically imports annotation classes.
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