\Drupal calls should be avoided in classes, use dependency injection instead

Created on 22 June 2023, about 1 year ago
Updated 13 July 2023, 12 months ago

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\computed_field\src\ComputedFieldBuilder.php
-----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------
71 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-----------------------------------------------------------------------------------------------

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\computed_field\src\Form\ComputedFieldForm.php
-------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------
300 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
301 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-------------------------------------------------------------------------------------------------

📌 Task
Status

Fixed

Version

4.0

Component

Code

Created by

🇮🇳India arti_parmar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @arti_parmar
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India arti_parmar

    Kindly review patch.

  • 🇮🇳India sidharth_soman Bangalore

    Patch #2 applies cleanly.

    However, there is still a dependency injection error left in one of the files. I am attaching the relevant screenshots.

    Hence, moving back to 'Needs Work'.

  • Status changed to Needs work 12 months ago
  • 🇬🇧United Kingdom joachim

    Thanks for the patch and the review.

    But please don't post screenshots that just show a patch applying or text!

  • Status changed to Needs review 12 months ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #2 by addressing #3, please review it.

    Thanks & Regards,
    Mrinalini

  • 🇬🇧United Kingdom joachim

    Committed, with the following fixes:

    1. +++ b/src/ComputedFieldBuilder.php
      @@ -18,15 +20,36 @@ class ComputedFieldBuilder implements TrustedCallbackInterface {
      +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
      +    return new static(
      +      $container->get('entity_type.manager'),
      +      $container->get('render_placeholder_generator')
      +    );
      

      That's wrong -- this is a service. The yml file needs to be changed. This will currently crash.

    2. +++ b/src/ComputedFieldBuilder.php
      @@ -68,13 +91,14 @@ class ComputedFieldBuilder implements TrustedCallbackInterface {
      -      ])];
      +      ]),
      +      ];
      

      That shouldn't be changed.

    Thanks everyone!

  • Status changed to Fixed 12 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024