- Issue created by @DhruvR
- 🇮🇳India vishal.kadam Mumbai
Thank you for applying!
Please read Review process for security advisory coverage: What to expect → for more details and Security advisory coverage application checklist → to understand what reviewers look for. Tips for ensuring a smooth review → gives some hints for a smoother review.
The important notes are the following.
- If you have not done it yet, you should enable GitLab CI for the project and fix the PHP_CodeSniffer errors/warnings it reports.
- For the time this application is open, only your commits are allowed.
- The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status will not be changed by this application; once this application is closed, you will be able to change the project status from Not covered to Opt into security advisory coverage. This is possible only 14 days after the project is created.
Keep in mind that once the project is opted into security advisory coverage, only Security Team members may change coverage. - Only the person who created the application will get the permission to opt projects into security advisory coverage. No other person will get the same permission from the same application; that applies also to co-maintainers/maintainers of the project used for the application.
- We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.
To the reviewers
Please read How to review security advisory coverage applications → , Application workflow → , What to cover in an application review → , and Tools to use for reviews → .
The important notes are the following.
- It is preferable to wait for a project moderator before posting the first comment on newly created applications. Project moderators will do some preliminary checks that are necessary before any change on the project files is suggested.
- Reviewers should show the output of a CLI tool → only once per application.
- It may be best to have the applicant fix things before further review.
For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues → .
- 🇮🇳India vishal.kadam Mumbai
Remember to change status, when the project is ready to be reviewed. In this queue, projects are only reviewed when the status is Needs review.
- 🇮🇳India DhruvR
I have implemented the required update in my module. Please have a look.
- 🇮🇳India vishal.kadam Mumbai
FILE: src/Controller/FileDownloadController.php
/** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager;
The parent class already has properties and methods for the entity type manager object. There is no need to redefine properties for the same purpose; instead, the parent class methods should be used.
/** * The controller constructor. */ public function __construct(
The documentation comment for constructors is not mandatory anymore, If it is given, the description must be “Constructs a new [class name] object”, where [class name] includes the class namespace.
- 🇮🇳India DhruvR
Hi Vishal
I've addressed the feedback in src/Controller/FileDownloadController.php:
Removed the redundant $entityTypeManager property and its injection via the constructor, as this is already available through ControllerBase::entityTypeManager().
Updated the constructor docblock to align with Drupal coding standards. The description now correctly reads:
Constructs a new FileDownloadController. - 🇮🇳India vishal.kadam Mumbai
Rest looks fine to me.
Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.
- 🇮🇳India DhruvR
Hello vishal
Just wanted to confirm anything else pending from my end.
- 🇮🇹Italy apaderno Brescia, 🇮🇹
- The following points are just a start and don't necessarily encompass all of the changes that may be necessary
- A specific point may just be an example and may apply in other places
- A review is about code that does not follow the coding standards, contains possible security issue, or does not correctly use the Drupal API
- The single review points are not ordered, not even by importance
src/Controller/FileDownloadController.php
Since that class does not use methods from the parent class, it does not need to use
ControllerBase
as parent class. Controllers do not need to have a parent class; as long as they implement\Drupal\Core\DependencyInjection\ContainerInjectionInterface
, they are fine.src/Plugin/Field/FieldFormatter/WebformDownloadFormatter.php
if (empty($webform_id)) { $this->messenger->addWarning($this->t('Please select a webform in the field formatter settings.')); return $elements; }
Should not that message be given from the form validation handler?
- 🇮🇳India DhruvR
Thank you for reviewing the code and sharing your observations!
I'd like to clarify both scenarios:
1. Use of Services like
entityTypeManager
,messenger
, etc.The services such as
$this->entityTypeManager
and$this->messenger
are correctly used here.
Since the formatter class extendsFormatterBase
(which implementsContainerFactoryPluginInterface
),
injecting these services via the constructor and using::create()
withContainerInterface
follows Drupal best practices.This method improves testability and adheres to Drupal's dependency injection principles.
2. Messenger Warning Inside
viewElements()
if (empty($webform_id)) { $this->messenger->addWarning($this->t('Please select a webform in the field formatter settings.')); return $elements; }
You're absolutely right that validation can be handled in the settings form.
In fact, thewebform_id
field is already marked as#required
:'#required' => TRUE,
However, the messenger warning inside
viewElements()
is a runtime safeguard that accounts for:- A webform being deleted after the field formatter was configured
- Configuration corruption or override (e.g., via config import)
It helps the formatter fail gracefully and informs site admins/editors clearly without causing rendering issues.
Summary
So yes, both uses are valid:
- Service injection is correct and standard
- Messenger warnings in
viewElements()
are an intentional fallback mechanism
Let me know if you’d prefer to enforce the webform existence with explicit validation in the settings form as well—happy to add that for extra robustness.
Thanks again!
- 🇮🇹Italy apaderno Brescia, 🇮🇹
// Load the file. $file = $this->entityTypeManager->getStorage('file')->load($file_id); if (!$file) { $this->messenger()->addError($this->t('File not found.')); throw new NotFoundHttpException(); }
$this->entityTypeManager
has not been initialized, which means the service has not been correctly injected. - 🇮🇳India DhruvR
Thank you for your comment!
I’d like to clarify that I’ve made the necessary adjustments in my code based on Vishal’s feedback in comment #6.
Since theentityTypeManager
is already available through the parent class (ControllerBase
),
I’ve removed the redundant property declaration and now directly use the inherited method.So in this case, the service is correctly injected via inheritance, and there’s no need for manual initialization.
Thanks again!
- 🇮🇹Italy apaderno Brescia, 🇮🇹
/** * Constructs a new FileDownloadController. * * @param \Symfony\Component\HttpFoundation\Session\Session $sessionManager * The session manager. */ public function __construct( Session $sessionManager, ) { $this->sessionManager = $sessionManager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container): self { return new self( $container->get('session'), ); } /** * Display a file securely in a new tab or download it. * * @param int $file_id * The file ID to display. * @param string $token * The security token. * * @return \Symfony\Component\HttpFoundation\Response * The file display response. */ public function download($file_id, $token) { // Load the file. $file = $this->entityTypeManager->getStorage('file')->load($file_id); if (!$file) { $this->messenger()->addError($this->t('File not found.')); throw new NotFoundHttpException(); }
$this->entityTypeManager
has not been initialized. - 🇮🇳India DhruvR
Hello avpaderno,
Thank you for the feedback! 🙏
I've updated the implementation to explicitly inject the entity_type.manager service via the constructor instead of relying on inheritance. This ensures $this->entityTypeManager is properly initialized and avoids any ambiguity.Let me know if there’s anything else that needs revision.
- 🇮🇹Italy apaderno Brescia, 🇮🇹
/** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager;
That property is already defined by the parent class.
public static function create(ContainerInterface $container): self { return new self( $container->get('session'), $container->get('entity_type.manager'), ); }
There is no need to inject the entity type manager: A method in the parent class returns that.
Either that, or the controller class does not use
ControllerBase
as parent class. Controller classes do not need to extendControllerBase
; as long as they implement\Drupal\Core\DependencyInjection\ContainerInjectionInterface
, they are fine.