Problem/Motivation

Drupal asked injection of:

  • \Drupal\Core\Render\Renderer
  • \Drupal\Core\Datetime\DateFormatter

Proposed resolution

Inject Renderer and Dateformater

Comments

thalles created an issue. See original summary.

thalles’s picture

Status: Needs work » Needs review
Issue tags: +ciandt-contrib
StatusFileSize
new3.53 KB

Follow the patch!

megachriz’s picture

Status: Needs review » Needs work

Thanks for the patch!

  1. +++ b/src/FeedTypeForm.php
    @@ -7,10 +7,12 @@ use Drupal\Core\Ajax\AjaxResponse;
    +use Drupal\Core\Datetime\DateFormatter;
    ...
    +use Drupal\Core\Render\Renderer;
    
    @@ -22,6 +24,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
    +   * @var \Drupal\Core\Datetime\DateFormatter
    
    @@ -36,17 +45,30 @@ class FeedTypeForm extends EntityForm {
    +   * @var \Drupal\Core\Render\Renderer
    ...
    +   * @param \Drupal\Core\Datetime\DateFormatter $date_formatter
    ...
    +   * @param \Drupal\Core\Render\Renderer $renderer
    ...
    +  public function __construct(DateFormatter $date_formatter, ConfigEntityStorageInterface $feed_type_storage, PluginFormFactory $factory, Renderer $renderer) {
    

    It is a best practice to require interfaces instead of classes in methods, if available.

  2. +++ b/src/FeedTypeForm.php
    @@ -327,7 +351,7 @@ class FeedTypeForm extends EntityForm {
    -    $renderer = \Drupal::service('renderer');
    +    $renderer = $this->renderer;
    

    I think instead of assigning $this->renderer to $renderer, the whole method might as well just use $this->renderer instead of $renderer.

  3. +++ b/src/FeedTypeForm.php
    @@ -262,7 +286,7 @@ class FeedTypeForm extends EntityForm {
    -    $values =& $form_state->getValues();
    +    $values = &$form_state->getValues();
    

    I'm not sure about this change. I thought =& $variable has a different meaning than = &$variable, but I don't remember what it was (have to wrap up now, I look it up later).

thalles’s picture

Status: Needs work » Needs review
StatusFileSize
new4.24 KB

Follow the patch!

  • MegaChriz committed 72c28fd on 8.x-3.x authored by thalles
    Issue #3021251 by thalles, MegaChriz: Fixed use dependency injection in...
megachriz’s picture

Status: Needs review » Fixed

Thanks! I moved the date formatter parameter in the constructor a bit further to the back to emphasize that the first two parameters are more important for FeedTypeForm. Not sure if there are coding standards for ordering constructor parameters, maybe it's just my personal preference to have more important parameters at the front.

thalles’s picture

ok!

Status: Fixed » Closed (fixed)

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