\Drupal::currentUser() static methods should be avoided in classes, use dependency injection instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bapi_22 created an issue. See original summary.

bapi_22’s picture

Assigned: bapi_22 » Unassigned
Status: Needs work » Needs review
FileSize
1.79 KB
iStryker’s picture

Version: 8.x-1.0 » 8.x-1.x-dev

Can you explain this a little more, maybe link to documentation that talks about Avoiding static calls inside a class method.

bapi_22’s picture

Hi iStryker,

Please go through the acquia documentation using below link.
https://docs.acquia.com/article/lesson-83-dependency-injection

iStryker’s picture

I am getting this error when I run the test

Drupal\Tests\draggableviews\Functional\DraggableviewsTest::testDraggableviewsContent
TypeError: Argument 1 passed to Drupal\draggableviews\Plugin\views\field\DraggableViewsField::__construct() must be a
n instance of Drupal\draggableviews\Plugin\views\field\AccountInterface, instance of Drupal\Core\Session\AccountProxy
given, called in /var/www/drupal8/modules/draggableviews/src/Plugin/views/field/DraggableViewsField.php on line 41

iStryker’s picture

Status: Needs review » Needs work

It actually throws error install Draggableview Demo module

bapi_22’s picture

I didn't checked at my end. Let check and will get back to you.

bapi_22’s picture

Status: Needs work » Needs review
FileSize
3.18 KB

Hi Tyler Struyk,

It was good catch. I was forgot to inject the EntityManager and LanguageManager from the parent Class.

Please use updated patch.

  • bapi_22 authored f6bf819 on 8.x-1.x
    Issue #2910127 by bapi_22: Avoid static call inside class method
    
iStryker’s picture

Status: Needs review » Fixed

Little clean up with Code standard checker and committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.