We can register a views.exectuable service in the container that uses a primitive factory class to return the a ViewExecutable instance. This could then be easily swapped out if people want to do that. For example, you could create a wrapper around the current ViewExectuble class to monitor and collect more performance data.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

This is a great idea. It's nice to get rid of that unnecessary hard dependency, and I can imagine this being useful in custom code.

Status: Needs review » Needs work

The last submitted patch, d8.view-exec-factory-service.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
FileSize
522 bytes
3.56 KB

Oops, thought I added that back in, must have forgot to save!

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/ViewExecutableFactory.phpundefined
@@ -0,0 +1,30 @@
+   * @return Drupal\views\ViewExecutable

Nitpick: Missing "\"

damiankloip’s picture

FileSize
3.56 KB

Damn you, dawehner ;)

damiankloip’s picture

FileSize
1.23 KB
4.8 KB

With a couple of unit tests too. What do you think?

damiankloip’s picture

FileSize
1.17 KB
4.79 KB

What a noisy issue, sorry. Now using $this->container in the test and fixed the typos.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -86,10 +86,10 @@ protected function setUp() {
-    $this->assertTrue($factory instanceof ViewExecutableFactory, 'An ViewExecutableFactory instance was returned from the container.');
...
+    $this->assertTrue($factory instanceof ViewExecutableFactory, 'A ViewExecutableFactory instance was returned from the container.');
...
-    $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'An ViewExecutable instance was returned from the factory.');
+    $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'A ViewExecutable instance was returned from the factory.');

I trust english people here, even they have some disagreements with the americans about certain aspects of the language :)

+++ b/core/modules/views/lib/Drupal/views/ViewsBundle.phpundefined
@@ -35,6 +35,8 @@ public function build(ContainerBuilder $container) {
+    $container->register('views.executable', 'Drupal\views\ViewExecutableFactory');

There should be some kind of naming standard for factories in the container (config.factory vs. queue) but yeah this is no critique on that patch.

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -86,10 +86,10 @@ protected function setUp() {
-    $this->assertTrue($factory instanceof ViewExecutableFactory, 'An ViewExecutableFactory instance was returned from the container.');
...
+    $this->assertTrue($factory instanceof ViewExecutableFactory, 'A ViewExecutableFactory instance was returned from the container.');
...
-    $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'An ViewExecutable instance was returned from the factory.');
+    $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'A ViewExecutable instance was returned from the factory.');

I trust english people here, even they have some disagreements with the americans about certain aspects of the language :)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

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