Commit 79ae23f2 authored by Jakob P's avatar Jakob P
Browse files

Issue #3118178 by Kate.Yemelyanenka, andregp, prabha1997, alanmoreira,...

Issue #3118178 by Kate.Yemelyanenka, andregp, prabha1997, alanmoreira, swatichouhan012, andrey.troeglazov: use dependency injection for renderer in FormWizardBase
parent eda8beb8
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\ctools\Event\WizardEvent;
use Drupal\Core\TempStore\SharedTempStoreFactory;
@@ -42,9 +43,9 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
   * @param null $step
   *   The current active step of the wizard.
   */
  public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match, $tempstore_id, $machine_name = NULL, $step = NULL) {
  public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, RouteMatchInterface $route_match, RendererInterface $renderer, $tempstore_id, EntityTypeManagerInterface $entity_type_manager, $machine_name = NULL, $step = NULL) {
    parent::__construct($tempstore, $builder, $class_resolver, $event_dispatcher, $route_match, $renderer, $tempstore_id, $machine_name, $step);
    $this->entityTypeManager = $entity_type_manager;
    parent::__construct($tempstore, $builder, $class_resolver, $event_dispatcher, $route_match, $tempstore_id, $machine_name, $step);
  }

  /**
@@ -57,6 +58,7 @@ abstract class EntityFormWizardBase extends FormWizardBase implements EntityForm
      'class_resolver' => \Drupal::service('class_resolver'),
      'event_dispatcher' => \Drupal::service('event_dispatcher'),
      'entity_type_manager' => \Drupal::service('entity_type.manager'),
      'renderer' => \Drupal::service('renderer'),
    ];
    // Keep the deprecated entity manager service as a parameter as well for
    // BC, so that subclasses still work.
+12 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\ctools\Ajax\OpenModalWizardCommand;
@@ -71,6 +72,13 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
   */
  protected $step;

  /**
   * Renderer.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
   *   Tempstore Factory for keeping track of values in each step of the
@@ -88,12 +96,13 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
   * @param null $step
   *   The current active step of the wizard.
   */
  public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, RouteMatchInterface $route_match, $tempstore_id, $machine_name = NULL, $step = NULL) {
  public function __construct(SharedTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, RouteMatchInterface $route_match, RendererInterface $renderer, $tempstore_id, $machine_name = NULL, $step = NULL) {
    $this->tempstore = $tempstore;
    $this->builder = $builder;
    $this->classResolver = $class_resolver;
    $this->dispatcher = $event_dispatcher;
    $this->routeMatch = $route_match;
    $this->renderer = $renderer;
    $this->tempstore_id = $tempstore_id;
    $this->machine_name = $machine_name;
    $this->step = $step;
@@ -108,6 +117,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
      'builder' => \Drupal::service('form_builder'),
      'class_resolver' => \Drupal::service('class_resolver'),
      'event_dispatcher' => \Drupal::service('event_dispatcher'),
      'renderer' => \Drupal::service('renderer'),
    ];
  }

@@ -336,8 +346,7 @@ abstract class FormWizardBase extends FormBase implements FormWizardInterface {
      '#wizard' => $this,
      '#cached_values' => $form_state->getTemporaryValue('wizard'),
    ];
    // @todo properly inject the renderer.
    $form['#prefix'] = \Drupal::service('renderer')->render($prefix);
    $form['#prefix'] = $this->renderer->render($prefix);
    return $form;
  }