Updated: Comment #N

Problem/Motivation

There are a lot of instances of code like the following in core:

    if (is_string($form_arg) && class_exists($form_arg)) {
      if (in_array('Drupal\Core\DependencyInjection\ContainerInjectionInterface', class_implements($form_arg))) {
        $form_arg = $form_arg::create(\Drupal::getContainer());
      }
      else {
        $form_arg = new $form_arg();
      }
    }

Proposed resolution

Introduce some generic way to do exactly these kind of code.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#116 interdiff-2165475-116.txt639 bytesdamiankloip
#116 2165475-116.patch35.13 KBdamiankloip
#114 2165475-114.patch35.08 KBdamiankloip
#112 2165475-112.patch35.03 KBdamiankloip
#110 controller_ressolver-2165475-110.patch35.11 KBdawehner
#107 interdiff-2165475-106.txt511 bytesdamiankloip
#107 2165475-106.patch35.06 KBdamiankloip
#104 interdiff-2165475-104.txt2.28 KBdamiankloip
#104 2165475-104.patch35.06 KBdamiankloip
#100 interdiff-2165475-100.txt759 bytesdamiankloip
#100 2165475-100.patch34.47 KBdamiankloip
#98 interdiff-2165475-98.txt635 bytesdamiankloip
#98 2165475-98.patch34.31 KBdamiankloip
#91 interdiff.txt2.15 KBdawehner
#91 class_resolver-2165475-91.patch34.33 KBdawehner
#84 2165475-84.patch34.32 KBdamiankloip
#83 2165475-82.patch0 bytesdamiankloip
#82 2165475-82.patch1.11 KBdamiankloip
#81 2165475-81.patch744.11 KBdamiankloip
#75 interdiff.txt814 bytesdawehner
#75 class_resolver-2165475-75.patch34.26 KBdawehner
#73 class-resolver-2165475-73.patch34.26 KBdawehner
#69 class-resolver-2165475-69.patch34.13 KBJalandhar
#66 interdiff-trailing-whitespace.txt967 bytesxjm
#66 class-resolver-2165475-66.patch34.14 KBxjm
#62 class_resolver-2165475-62.patch34.36 KBmartin107
#57 class_resolver-2165475-57.patch35.01 KBmartin107
#52 interdiff-2165475-52.txt491 bytesdamiankloip
#52 2165475-52.patch35 KBdamiankloip
#49 interdiff-46-49.txt5.55 KBmartin107
#49 class_resolver-2165475-49.patch35 KBmartin107
#46 interdiff.txt2.16 KBjibran
#46 class_resolver-2165475-46.patch32.45 KBjibran
#45 interdiff.txt1.94 KBdawehner
#45 class_resolver-2165475-45.patch32.28 KBdawehner
#42 interdiff-39-42.txt905 bytesmartin107
#42 class_resolver-2165475-42.patch30.34 KBmartin107
#39 interdiff.txt5.04 KBmartin107
#39 class_resolver-2165475-39.patch29.46 KBmartin107
#36 interdiff-32.36.txt7.34 KBmartin107
#36 class_resolver-2165475-36.patch29.19 KBmartin107
#32 interdiff-29-32.txt1.69 KBmartin107
#32 class_resolver-2165475-32.patch22.68 KBmartin107
#29 interdiff-27-29.txt1.28 KBmartin107
#29 class_resolver-2165475-29.patch22.97 KBmartin107
#27 interdiff-25-27.txt487 bytesmartin107
#27 class_resolver-2165475-27.patch22.56 KBmartin107
#25 class_resolver-2165475-24.patch22.58 KBdawehner
#23 class_resolver.patch23.78 KBdawehner
#18 interdiff.txt3.94 KBtim.plunkett
#18 2165475-generic_resolver-18.patch18.07 KBtim.plunkett
#16 2165475-generic_resolver.patch15.8 KBdawehner
#14 2165475-controller_resolver.patch15.49 KBdawehner
#9 controller-2165475-9.patch5.75 KBtim.plunkett
#6 controller_resolver-2165475.patch15.64 KBdawehner
#5 interdiff.txt1.14 KBdawehner
#4 controller_resolver-2165475.patch15.18 KBdawehner
#2 interdiff.txt11.52 KBtim.plunkett
#2 controller-2165475-2.patch14.04 KBtim.plunkett
#1 foo.patch2.52 KBdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

FileSize
2.52 KB

This is for example useful one some page manager functionality.

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +DX (Developer Experience)
FileSize
14.04 KB
11.52 KB

I like it!
I rounded out the usage to show it off better.

The last submitted patch, 2: controller-2165475-2.patch, failed testing.

dawehner’s picture

Fixed the bit in the installer.

dawehner’s picture

FileSize
1.14 KB

Missing interdiff

dawehner’s picture

Rerolled with a nice suggestion from chx!

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Nice change!

No interdiff, but the change was swapping

if (in_array('Drupal\Core\DependencyInjection\ContainerInjectionInterface', class_implements($class))) {
for
if (is_subclass_of($class, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {

sun’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
    @@ -150,6 +141,23 @@ protected function createController($controller) {
    +  public function getInstanceFromClassName($class) {
    

    Shouldn't this be a static method?

    It doesn't appear to use or touch the state of the instantiated class in any way, it's just an I/O utility operation?

  2. +++ b/core/lib/Drupal/Core/Entity/EntityManager.php
    @@ -129,8 +137,10 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
    -  public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) {
    +  public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager, ControllerResolverInterface $controller_resolver) {
    
    @@ -138,6 +148,7 @@ public function __construct(\Traversable $namespaces, ContainerInterface $contai
    +    $this->controllerResolver = $controller_resolver;
    

    Injecting an entire ControllerResolver instance just to be able to figure out how to instantiate certain classes based on a hard-coded pattern is a completely unnecessary dependency?

    Am I missing something big here?

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
5.75 KB

A completely different approach, via @msonnabaum.

dawehner’s picture

Not sure what the advantages of static methods would be.

Status: Needs review » Needs work

The last submitted patch, 9: controller-2165475-9.patch, failed testing.

Crell’s picture

Honestly there aren't any. Objects aren't something you use only when you have state. They're something you use to provide a mostly-free layer of indirection, or to encapsulate functionality.

And this should still be done upstream...

dawehner’s picture

Honestly there aren't any. Objects aren't something you use only when you have state. They're something you use to provide a mostly-free layer of indirection, or to encapsulate functionality.

Well, the controller resolver has state, maybe this is just a sign that this method does not belong into this class.

dawehner’s picture

Status: Needs work » Needs review
FileSize
15.49 KB

Honestly there aren't any. Objects aren't something you use only when you have state. They're something you use to provide a mostly-free layer of indirection, or to encapsulate functionality.

We also have the status of the container.

Status: Needs review » Needs work

The last submitted patch, 14: 2165475-controller_resolver.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
15.8 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 16: 2165475-generic_resolver.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
18.07 KB
3.94 KB

Fixed the unit test.

sun’s picture

Something still feels wrong with this approach. Perhaps my interpretation is wrong, but let me try to think aloud (sorry in advance if I'm not using correct/proper terminologies):

  1. ControllerResolver is a facility to resolve controllers for handling a request.
  2. It does not look correct to me that low-level services like EntityManager and FormBuilder suddenly need this dependency. Especially EntityManager should be decoupled from the http/request architecture.
  3. In fact, EntityManager is a "controller resolver" service of its own. Thus, a controller resolver gets a controller resolver injected? In addition, the "controller" (handler) terminology of the Entity API is further distorted by mixing actual request controllers into it?
  4. ControllerResolver gets the whole service container injected, which means that aforementioned classes (and possibly more when follow-up issues will apply this pattern elsewhere) indirectly depend on the service container now. I thought we already had decided long ago that D8 should not result in a system that gets the DI container injected into almost everything?
  5. It looks weird that the $class argument of getInstanceFromClassName($class) can also be a service ID. That is a typical double-purpose case, which results in a unclean API. In addition, I also wonder about unforeseen name clashes and false-positive $class == $service_id cases.
  6. Ultimately, I've the impression that this patch turns ControllerResolver into a Drupal-esque ContainerNG, with the primary purpose of allowing people to say:

    Injecting the ControllerResolver into this class here is OK, because as you can see, we're not injecting the service container.

All of this sounds very concerning to me. Please let me know where I'm wrong.

tim.plunkett’s picture

Responding to 19.4 for now, I'll be back for the rest

which means that aforementioned classes ... indirectly depend on the service container now.

Umm. HtmlFormController and EntityManager already had $this->container. The others called \Drupal::getContainer(). This is giving them *less* surface area, not more.

twistor’s picture

+++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
@@ -150,6 +141,28 @@ protected function createController($controller) {
+      // @todo Remove the second in_array() once that interface has been removed.
+      if (is_subclass_of($class, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {
+        $instance = $class::create($this->container);

This comment?

I agree that ControllerResolver is not an ideal place to stick this bit of functionality, however, anything creating ContainerInjectionInterface objects has an obvious dependency on the container.

Status: Needs review » Needs work

The last submitted patch, 18: 2165475-generic_resolver-18.patch, failed testing.

dawehner’s picture

FileSize
23.78 KB

This patch started to move everything into a class_resolver so we get rid of controller problem.

cordoval’s picture

is there a github mirror PR when we can see the diff more beautifully? would help a lot

dawehner’s picture

Status: Needs work » Needs review
FileSize
22.58 KB

Rerolled the patch.

Status: Needs review » Needs work

The last submitted patch, 25: class_resolver-2165475-24.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
22.56 KB
487 bytes

Corrected mismatch in arguments between constructor definition and arguments supplied to controller_resolver service definition.

Status: Needs review » Needs work

The last submitted patch, 27: class_resolver-2165475-27.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
22.97 KB
1.28 KB

class_resolver :-

service definition argument... a service container ... fair enough.
class_resolver constructor missing ... opps container gets dropped on floor.

Fixed.

dawehner’s picture

Status: Needs review » Needs work

Good catch! On top of that it would be great to write some test coverage.

+++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
@@ -15,6 +16,20 @@
 
   /**
+   * The container from where services are loaded
+   * @var ContainerInterface
+   */
+  protected $container;
+
+  /**
+   * Constructs a new ControllerResolver.
+   *
+   * @param ContainerInterface $container A ContainerInterface instance
+   */
+  public function __construct(ContainerInterface $container) {
+    $this->container = $container;
+  }
+  /**

Note: we can use the ContainerAwareTrait from Symfony\Component\DependencyInjection instead.

Opened a new issue for other instances: #2229183: use ContainerAwareTrait instead of extending ContainerAware

+++ b/core/core.services.yml
@@ -230,6 +230,9 @@ services:
     arguments: ['@service_container']

Let's use setter injection instead so we do something similar as all the other places in core.

The last submitted patch, 29: class_resolver-2165475-29.patch, failed testing.

martin107’s picture

No Need to use ContinaerAwareTraits... as we are extending ContainerAware..
In this case less is more... So I have backed out the constructor and altered the service definition.

Facepalm Adding traits -- results in duplication of functionality errors .. I wish I had seen that before I did it

abstract class ContainerAware implements ContainerAwareInterface
{
    /**
     * @var ContainerInterface
     *
     * @api
     */
    protected $container;

    /**
     * Sets the Container associated with this Controller.
     *
     * @param ContainerInterface $container A ContainerInterface instance
     *
     * @api
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
martin107’s picture

Status: Needs work » Needs review

The last submitted patch, 23: class_resolver.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 32: class_resolver-2165475-32.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
29.19 KB
7.34 KB

This change addresses one flaw... its a simple change but requires lots of changes to variables up and down the lasagne.

This needs careful review as I wanted to find a better solution but could not

HtmlFormController.php requires both a

$classResolver ...see getFormObject()

AND

$controllerResolver... as it calls its parent::__contruct on FormController

IT was previous fed only a ControllerResolver

NB HtmlFormController:getFormObject(Request $request, $form_arg) --- $request is an unused variable.. something wrong there...

Status: Needs review » Needs work

The last submitted patch, 36: class_resolver-2165475-36.patch, failed testing.

dawehner’s picture

+++ b/core/lib/Drupal/Core/EventSubscriber/ContentFormControllerSubscriber.php
@@ -46,14 +47,17 @@ class ContentFormControllerSubscriber implements EventSubscriberInterface {
+  public function __construct(ContainerInterface $container, ClassResolverInterface $classResolver, ControllerResolverInterface $controllerResolver, FormBuilderInterface $form_builder) {

Note, we don't use camelCased variables as method parameters.

martin107’s picture

Three things

> -    arguments: ['@container.namespaces', '@service_container', '@module_handler', '@cache.default', '@language_manager', '@string_translation']
> +    arguments: ['@container.namespaces', '@service_container', '@module_handler', '@cache.default', '@language_manager', '@string_translation', '@class_resolver']

1) Single line reroll from core.services.yml due to class with cache.default being renamed. The interdiff.txt is from this point onwards

2) Arguement parameters no longer camel cased. ( Thank you for pointing that out )

-    $this->formBuilder = new TestFormBuilder($this->moduleHandler, $this->keyValueExpirableFactory, $this->eventDispatcher, $this->urlGenerator, $this->translationManager, $this->controllerResolver, $this->csrfToken, $this->httpKernel);
+    $this->formBuilder = new TestFormBuilder($this->moduleHandler, $this->keyValueExpirableFactory, $this->eventDispatcher, $this->urlGenerator, $this->translationManager, $this->classResolver, $this->csrfToken, $this->httpKernel);

3) Next issue on the hit list...from core/tests/Drupal/Tests/Core/Form/FormTestBase.php

Previously controllerResolver was supplied as parameter, when classResolver was needed.

These recent patches are slowly correcting issues... the tesbot error logs are getting shorter. BUT Further failures are expected.

martin107’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 39: class_resolver-2165475-39.patch, failed testing.

martin107’s picture

> function template_preprocess_views_view(&$variables) {
>      }
>  
>      $container = \Drupal::getContainer();
> -    $form_object = new ViewsForm($container->get('controller_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display);
> +    $form_object = new ViewsForm($container->get('class_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display);
>      $form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
>      // The form is requesting that all non-essential views elements be hidden,
>      // usually because the rendered step is not a view result.

This controller/class resolver bug is common to many tests.

martin107’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 42: class_resolver-2165475-42.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
32.28 KB
1.94 KB

Fixed the failures.

jibran’s picture

So another DIY. If my doc changes are fine then this patch is RTBC.

  1. +++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
    @@ -10,6 +10,8 @@
    +use \Drupal\Core\Controller\ControllerResolverInterface;
    

    \ Not needed

  2. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolverInterface.php
    @@ -0,0 +1,22 @@
    +  public function getInstanceFromClassName($class);
    

    @param @throw and @return missing.

  3. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
    @@ -0,0 +1,43 @@
    +      // @todo Remove the second in_array() once that interface has been removed.
    

    more then 80 chars.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
    @@ -31,10 +33,18 @@ class HtmlFormController extends FormController {
    +   * @var  Drupal\Core\DependencyInjection\ClassResolverInterface;
    

    There are two spaces here.

  2. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
    @@ -0,0 +1,44 @@
    +use Symfony\Component\DependencyInjection\ContainerAware;
    +use Symfony\Component\DependencyInjection\ContainerAwareInterface;
    ...
    +class ClassResolver extends ContainerAware implements ClassResolverInterface, ContainerAwareInterface {
    

    Why both?

  3. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
    @@ -0,0 +1,44 @@
    +      // @todo Remove the second in_array() once that interface has been
    +      //   removed.
    

    We removed this a looooong time ago

  4. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
    @@ -0,0 +1,44 @@
    +    return $instance;
    +  }
    +}
    

    Missing blank line

  5. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolverInterface.php
    @@ -0,0 +1,30 @@
    +   * @throws \InvalidArgumentException
    

    This needs to explain when it is thrown

  6. +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php
    @@ -64,6 +64,13 @@
    +   * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Controller\ControllerResolverInterface
    

    Please swap the order of these two

martin107’s picture

Assigned: Unassigned » martin107

assigning to myself while I resolve #47

martin107’s picture

Assigned: martin107 » Unassigned
FileSize
35 KB
5.55 KB

All issues fixed....

I hope you don't consider this feature creep but in fixing #47.6,

once I swapped the type hinting to reflect the coding standard I have to make the file look consistent and so I had to also swap 10 others

jibran’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +API clean-up

Thanks @martin107 for fixing the issues. I have only made some doc changes so I think I can RTBC this patch.

dawehner’s picture

Awesome, thank you for pushing that forward!

damiankloip’s picture

FileSize
35 KB
491 bytes

Patch looks great, just did a full review and test.

I'm not sure how much getClassResolverStub() will actually be used, but makes sense to keep it I think.

+1 - Just added one missing space as I had the patch applied!

dawehner’s picture

Most trivial interdiff of the month :P

damiankloip’s picture

It's all about the finer details :D

damiankloip’s picture

Title: Provide some generic class resolver » Provide a generic class resolver

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: 2165475-52.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
35.01 KB

Reroll.

martin107’s picture

Status: Needs review » Reviewed & tested by the community

Trivial reroll.... so back to rtbc

damiankloip’s picture

Yep, looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: class_resolver-2165475-57.patch, failed testing.

martin107’s picture

Assigned: Unassigned » martin107

I will do the reroll

martin107’s picture

Status: Needs work » Needs review
FileSize
34.36 KB

Lots of niggly changes any of which could blow up testing

so manual testing :-

1) It installs :-)
2) ControllerResolverTest passes
3) EntityManagerTest passes

Lets see what test bot says

martin107’s picture

Assigned: martin107 » Unassigned

Green.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

alexpott’s picture

xjm’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
34.14 KB
967 bytes

I think this is significant enough to maybe merit a change record for the addition?

Also, here's a reroll without the trailing whitespace. ;)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 66: class-resolver-2165475-66.patch, failed testing.

Jalandhar’s picture

Status: Needs work » Needs review
FileSize
34.13 KB

Updating rerolled patch.

martin107’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good so back to RTBC

dawehner’s picture

Thank you for rerolling!

catch’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
    @@ -109,31 +121,17 @@ protected function createController($controller) {
    +    $controller = $this->classResolver->getInstanceFromClassName($class_or_service);
    

    Shouldn't the method be getInstanceFromClassOrServiceName()?

  2. +++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
    @@ -53,11 +63,7 @@ public function __construct(ControllerResolverInterface $resolver, ContainerInte
         }
    

    getInstanceFromClassName() does class_exists() and also handles services, so can't this just use the method? If the logic is different it could use a comment as to what needs changing.

  3. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolverInterface.php
    @@ -0,0 +1,31 @@
    +   *   A class name.
    

    Or service name right? Docs could be much clearer about this accepting both.

Also:

+    if ($this->container->has($class)) {
+      $instance = $this->container->get($class);
+    }

This looks like it could be a performance regression. When you request a service that doesn't exist, Symfony runs a levenshtein comparison on the string against all services to create suggestions as part of the exception it throws for missing services.

I didn't check if that's the case here, but it might work out cheaper to do the class_exists() check first. At least, this needs checking.

dawehner’s picture

Status: Needs work » Needs review
FileSize
34.26 KB

Shouldn't the method be getInstanceFromClassOrServiceName()?

Went with getInstanceFromDefinition which is more similar with the controller resolver.

This looks like it could be a performance regression. When you request a service that doesn't exist, Symfony runs a levenshtein comparison on the string against all services to create suggestions as part of the exception it throws for missing services.

Doesn't the has call, which is pretty straightforward:

    public function has($id)
    {
        $id = strtolower($id);

        return isset($this->services[$id])
            || array_key_exists($id, $this->services)
            || isset($this->aliases[$id])
            || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')
        ;
    }

ensures that you never call a non-existing service?

Status: Needs review » Needs work

The last submitted patch, 73: class-resolver-2165475-73.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
34.26 KB
814 bytes

meh

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Needs review » Needs work

This needs a reroll after #2209977: Move form validation logic out of FormBuilder into a new class, and will need another one after #2257835: Move form submission logic out of FormBuilder into a new class which is RTBC, so I'm just going to wait and do that

dawehner’s picture

This one has been RTBC for ages, well.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Okay, if someone else wants to reroll it before then, feel free. I just know that the constructor signature of FormBuilder *just* changed, and is about to change again.

dawehner’s picture

Yeah, let's waste all the time!

dawehner’s picture

Status: Needs work » Needs review

Let's make it like the professionals and mark the other issue as being blocked on this one.

damiankloip’s picture

FileSize
744.11 KB

Here is a reroll either way. Entity Manager needed it too.

damiankloip’s picture

FileSize
1.11 KB

Usually good to rebase that branch too.

damiankloip’s picture

FileSize
0 bytes

FFS!!

damiankloip’s picture

FileSize
34.32 KB

Meh. SOrry for inappropriate noise.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

HA, you went through all the steps!!

The last submitted patch, 83: 2165475-82.patch, failed testing.

The last submitted patch, 82: 2165475-82.patch, failed testing.

The last submitted patch, 81: 2165475-81.patch, failed testing.

damiankloip’s picture

Thanks whoever did mass cancelling!!

catch’s picture

Status: Reviewed & tested by the community » Needs work

Looks like there's still some cruft that could be removed:

  1. +++ b/core/lib/Drupal/Core/Controller/HtmlFormController.php
    @@ -52,16 +62,7 @@ public function __construct(ControllerResolverInterface $resolver, ContainerInte
         // If this is a class, instantiate it.
    

    Comment no longer applies.

  2. +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php
    @@ -0,0 +1,47 @@
    +    if ($this->container->has($definition)) {
    

    You're right that the has() call protects against needless container lookups, sorry for false alarm.

  3. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -129,13 +140,9 @@ public function __construct(FormValidatorInterface $form_validator, ModuleHandle
         if (is_string($form_arg) && class_exists($form_arg)) {
    

    Do we really still need the class_exists() here? That should be covered.

  4. +++ b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php
    @@ -169,17 +170,12 @@ public function submitForm(array &$form, array &$form_state) {
         if (class_exists($form_step_class)) {
    

    Again is the class_exists() necessary?

  5. +++ b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php
    @@ -169,17 +170,12 @@ public function submitForm(array &$form, array &$form_state) {
    +    return \Drupal::getContainer()->get($form_step_class);
    

    Why is this needed if the class resolver can get a service anyway before it reaches here?

dawehner’s picture

Status: Needs work » Needs review
FileSize
34.33 KB
2.15 KB

Good points.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Ah, nice one.
Thanks @catch!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 91: class_resolver-2165475-91.patch, failed testing.

catch’s picture

The last submitted patch, 91: class_resolver-2165475-91.patch, failed testing.

damiankloip’s picture

The last submitted patch, 91: class_resolver-2165475-91.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
34.31 KB
635 bytes

Do we really still need the class_exists() here? That should be covered.

That is what was keeping the logic to return the original string for the form ID if just a string is provided. Otherwise, we assume it's a class when it's just a string like 'foo' or something. See FormBuilderTest::testGetFormIdWithString(). So we can add this back like this patch does, or re-think how we deal with this using the ClassResolver.

catch’s picture

OK so let's keep that as is, however it could use a comment containing the basics of #98.

damiankloip’s picture

FileSize
34.47 KB
759 bytes

?

catch’s picture

Status: Needs review » Reviewed & tested by the community

Yeah that's great. Back to RTBC.

damiankloip’s picture

Super.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 100: 2165475-100.patch, failed testing.

damiankloip’s picture

FileSize
35.06 KB
2.28 KB

Rerolled. Also, I think we can just remove the container aware stuff for the controller resolver now as the class resolver handles that?

damiankloip’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 104: 2165475-104.patch, failed testing.

damiankloip’s picture

FileSize
35.06 KB
511 bytes

Silly.

damiankloip’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 107: 2165475-106.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
35.11 KB

Maybe this time ...

Status: Needs review » Needs work

The last submitted patch, 110: controller_ressolver-2165475-110.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
35.03 KB

Another reroll of that.

Status: Needs review » Needs work

The last submitted patch, 112: 2165475-112.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
35.08 KB

Now I forgot to pull. Here is a re-re-base.

Status: Needs review » Needs work

The last submitted patch, 114: 2165475-114.patch, failed testing.

damiankloip’s picture

FileSize
35.13 KB
639 bytes
damiankloip’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

moeh

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 15cf730 and pushed to 8.x. Thanks!

  • Commit 15cf730 on 8.x by alexpott:
    Issue #2165475 by damiankloip, dawehner, martin107, tim.plunkett, jibran...

Status: Fixed » Closed (fixed)

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