Problem/Motivation

While fixing #3386719: Fatal error when viewing a static_page revision due to core type upcasting change, eager contributors wanted to convert StaticPageSubscriber to use DI. I also ran into this while getting a green pipeline at #3563026: Enable GitLab CI for static_page since phpstan was complaining about the \Drupal:: calls.

Steps to reproduce

Proposed resolution

  1. Use DI not \Drupal:: in src/EventSubscriber/StaticPageSubscriber.php
  2. Remove that warning from phpstan-baseline.neon

Remaining tasks

Move commits/diff about DI from #3386719: Fatal error when viewing a static_page revision due to core type upcasting change into here.

User interface changes

API changes

Data model changes

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

dww created an issue. See original summary.

dww’s picture

Status: Active » Postponed

Moved the DI changes from #3386719: Fatal error when viewing a static_page revision due to core type upcasting change to here. However, this is still gonna conflict with #3386719, so let's resolve that, first. Also, still need to remove the DI stuff from the phpstan baseline.

joelpittet’s picture

Is it ok to expand the scope a bit and deal with StaticPageSettingsForm as well @dww?

dww’s picture

Re: #4: Slightly confused, I don't see any \Drupal:: in StaticPageSettingsForm. What else needs DI in there?

joelpittet’s picture

@dww sorry it's not Drupal static. Here is what I had in mind for NodeType the gist as there is a constructor change too:

@@ -35,7 +45,8 @@ class StaticPageSettingsForm extends ConfigFormBase {
    */
   public static function create(ContainerInterface $container) {
     return new static(
-      $container->get('entity_field.manager')
+      $container->get('entity_field.manager'),
+      $container->get('entity_type.manager')
     );
   }

@@ -59,7 +70,7 @@ class StaticPageSettingsForm extends ConfigFormBase {
   public function buildForm(array $form, FormStateInterface $form_state) {

     $config = $this->config('static_page.fields');
-    $types = NodeType::loadMultiple();
+    $types = $this->entityTypeManager->getStorage('node_type')->loadMultiple();

     $fields_config = $config->get('fields');
     $form['help'] = [
dww’s picture

Title: Use dependency injection in StaticPageSubscriber » Use dependency injection in StaticPageSubscriber and StaticPageSettingsForm

Oh, gotcha. Sure, we can fix both in here. Thanks!

dww’s picture

Status: Postponed » Needs review

Rebased after recent merges. Fixed StaticPageSettingsForm.

  • dww committed 969de68c on 8.x-1.x
    task: #3563027 Use dependency injection in StaticPageSubscriber and...

dww’s picture

Status: Needs review » Fixed

Merged. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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