use dependency injection to avoid upgrade problems to newer version.

Example:
File : /src/Plugin/views/display/DataExport.php

use Drupal\Core\Utility\Token;

\Drupal::token()->replace($filename, ['view' => $view] instead use $this->token->replace[$filename, ['view' => $view]]

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Vernit created an issue. See original summary.

vernit’s picture

Issue summary: View changes
vernit’s picture

Issue summary: View changes
amateichuk’s picture

Status: Active » Closed (works as designed)

In static methods we can't use dependency injection

benstallings’s picture

Version: 8.x-1.0-beta3 » 8.x-2.x-dev
Assigned: Unassigned » benstallings
Status: Closed (works as designed) » Active

OK, but not all of the methods in that class are static! And the parent class already implements ContainerFactoryPluginInterface, so all we need to do is use the $instance = parent::create() pattern.

  • defineOptions(), optionsSummary(), and buildOptionsForm() need the module_handler service injected
  • buildOptionsForm() also needs the stream_wrapper_manager and plugin.manager.facets.facet_source services injected
benstallings’s picture

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

whoops, wrong version

benstallings’s picture

Assigned: benstallings » Unassigned
Status: Active » Needs review
steven jones’s picture

Status: Needs review » Needs work

@benstallings thanks for the effort here, but there are still some places where we're not using dependency injection in this class at least, specifically the usages of the token service originally raised in this issue.

steven jones’s picture

Status: Needs work » Needs review

Ah, but of course that's exactly where we can't use DI, because the methods are static.

steven jones’s picture

Status: Needs review » Fixed

Nice, thanks Ben.

Status: Fixed » Closed (fixed)

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

steven jones’s picture

Related issues: +#3552653: Release 8.x-1.7