Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Needs review
FileSize
37.84 KB

Here is a patch that converts all services defined by views.

dawehner’s picture

FileSize
46.23 KB

Let's introduce a Views helper object, similar to Drupal, which does what we need.

I choosed to have one method for all plugin types, because 10 methods just one for each plugin type causes other issues:

  • You still don't have a generic method, which can accept the $type parameter
  • It let's the class feel to be complicated

Opened a follow up to inject all the plugin managers (as all of them are needed at one point) into the view executable.
#1938058: Inject all plugin managers to the view executable object.

Crell’s picture

+++ b/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php
@@ -40,7 +41,7 @@ public function query() {
-    $views_data = drupal_container()->get('views.views_data')->get($this->table);
+    $views_data = Views::viewsData()->get('views.views_data')->get($this->table);

This looks a bit off. Shouldn't it be Views::viewsData()->get()?

+++ b/core/modules/views/lib/Drupal/views/Views.php
@@ -0,0 +1,59 @@
+  /**
+   * Returns a plugin manager for a certain views plugin type.
+   *
+   * @param string $type
+   *   The plugin type, for example filter.
+   *
+   * @return \Drupal\views\Plugin\ViewsPluginManager
+   */
+  public static function pluginManager($type) {
+    return Drupal::service('plugin.manager.views.' . $type);
+  }

Do any of these services have a subclass, or are they all ViewsPluginManager? If subclasses, then it may make sense to give them their own utility wrappers.

At least until Views is fully injected and this class goes away. :-)

dawehner’s picture

FileSize
46.21 KB
812 bytes

Regarding the first point: you are absolute right about that!

Regarding the second point: They all do indeed have the same class, see the bundle,
though there are issues which creates custom ones for certain needs, but yeah then we can use them.

foreach (ViewExecutable::getPluginTypes() as $type) {
      $container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\ViewsPluginManager')
        ->addArgument($type)
        ->addArgument('%container.namespaces%');
    }
damiankloip’s picture

Patch is looking awesome, a views wrapper is nice idea too. Just a couple of the obligatory nitpicks :

+++ b/core/modules/views/lib/Drupal/views/Views.phpundefined
@@ -0,0 +1,59 @@
+namespace Drupal\views;

Just a space after the docblock here.

+++ b/core/modules/views/lib/Drupal/views/Views.phpundefined
@@ -0,0 +1,59 @@
+   * Returns a view executable factory service.

'a' or 'the'? We are only going to have one.

+++ b/core/modules/views/lib/Drupal/views/Views.phpundefined
@@ -0,0 +1,59 @@
+   * Returns a view analyzer.

'Return the views analyzer service'?

+++ b/core/modules/views/lib/Drupal/views/Views.phpundefined
@@ -0,0 +1,59 @@
+   * Returns a plugin manager for a certain views plugin type.

same, should we use 'the' instead of 'a'?

+++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/Ajax/EditDetails.phpundefined
@@ -77,7 +78,7 @@ public function submitForm(array &$form, array &$form_state) {
+    $bases = Views::viewsData()->fetchBaseTables();

Stuff like this looks soooo much nicer! :)

tim.plunkett’s picture

Title: Replace drupal_container->get() with Drupal::service() » Replace View's usage of drupal_container->get() with Drupal::service()
dawehner’s picture

FileSize
1.19 KB
46.21 KB

Good points damian. I really like "the" better here.

Status: Needs review » Needs work

The last submitted patch, drupal-1938030-7.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
472 bytes
46.38 KB

One single Views was forgot to be used :(

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

Nice clean up.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks.

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