Problem/Motivation

As we have seen in #2781207: Use class resolver for abstracted Content Moderation classes the class_resolver

Proposed resolution

Let's add it to \Drupal

Advantages

  • Discoverability
  • Documentability

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

timmillwood’s picture

Status: Active » Needs review
FileSize
578 bytes

Initial implementation.

Did wonder if we should return the basic class resolver object, or accept a class name and pass directly to getInstanceFromDefinition()? Went for returning a basic class resolver object.

dawehner’s picture

+1 for not doing some additional magic beside getting the service from the container.

timmillwood’s picture

FileSize
1.34 KB
794 bytes

Adding test.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

WFM

dawehner’s picture

Status: Reviewed & tested by the community » Needs work

Wait, actually I think we should document legit usecases of this function

The last submitted patch, 2: 2785355-2.patch, failed testing.

The last submitted patch, 4: 2785355-3.patch, failed testing.

The last submitted patch, 4: 2785355-3.patch, failed testing.

The last submitted patch, 4: 2785355-3.patch, failed testing.

timmillwood’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
551 bytes

Adding basic docs to the method.

The last submitted patch, 2: 2785355-2.patch, failed testing.

dawehner’s picture

Small expansion of the documentation.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

WFM

As long as the test passes, RTBC!

borisson_’s picture

+++ b/core/lib/Drupal.php
@@ -300,6 +300,22 @@ public static function cache($bin = 'default') {
+   * an object of a class that implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface.

Nitpick: I think the classname should be on the next line to respect 80 cols.

timmillwood’s picture

@borisson_ IIRC the 80 cols restriction is only for the first line, but I might be wrong. I did think about putting the class name on the third line, but that then made the third line longer than the second, which looked odd.

Anyway, I'll leave it up to the committer to do on commit.

dawehner’s picture

Nope the 80 chars limit is for every line.

Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, with a few exceptions (noted in the Tag Reference below).

from https://www.drupal.org/node/1354

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 2785355-13.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.68 KB
696 bytes

Fixing #15.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @claudiu.cristea

xjm’s picture

Status: Reviewed & tested by the community » Fixed

I was hesitant about this issue based on the title/summary, but the documentation in the patch itself makes a compelling case for this API addition. Committed 9d3d930 and pushed to 8.3.x. Thanks!

  • xjm committed 9d3d930 on 8.3.x
    Issue #2785355 by timmillwood, dawehner, claudiu.cristea, borisson_:...
xjm’s picture

+++ b/core/tests/Drupal/Tests/Core/DrupalTest.php
@@ -102,7 +102,7 @@ public function testDatabase() {
-   * Tests the service() method.
+   * Tests the cache() method.

Well this change was out of scope, but oops, committed anyway. :)

Status: Fixed » Closed (fixed)

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