From 9ac5c2b9de355972a50696e32fca471d8bdd24bd Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 29 Oct 2019 09:32:44 +0000
Subject: [PATCH] Issue #2723553 by kim.pepper, jibran, mattc321: Trigger
 deprecated warning for ViewsData::get(NULL)

---
 core/modules/views/src/Plugin/ViewsHandlerManager.php         | 2 +-
 core/modules/views/src/ViewsData.php                          | 4 +++-
 core/modules/views/src/ViewsDataHelper.php                    | 2 +-
 .../views/tests/src/Functional/Handler/HandlerAllTest.php     | 2 +-
 core/modules/views/tests/src/Unit/ViewsDataHelperTest.php     | 2 +-
 core/modules/views/tests/src/Unit/ViewsDataTest.php           | 3 +++
 6 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php
index bfc859227a18..f94ff5173ea7 100644
--- a/core/modules/views/src/Plugin/ViewsHandlerManager.php
+++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php
@@ -82,7 +82,7 @@ public function getHandler($item, $override = NULL) {
     $table = $item['table'];
     $field = $item['field'];
     // Get the plugin manager for this type.
-    $data = $this->viewsData->get($table);
+    $data = $table ? $this->viewsData->get($table) : $this->viewsData->getAll();
 
     if (isset($data[$field][$this->handlerType])) {
       $definition = $data[$field][$this->handlerType];
diff --git a/core/modules/views/src/ViewsData.php b/core/modules/views/src/ViewsData.php
index 09522b984f5a..9552ffddc13c 100644
--- a/core/modules/views/src/ViewsData.php
+++ b/core/modules/views/src/ViewsData.php
@@ -137,12 +137,14 @@ public function getAll() {
    *   removed in 9.0.0. Use getAll() instead.
    *
    * @see https://www.drupal.org/node/2723553
+   * @see https://www.drupal.org/node/3090442
    *
    * @return array
    *   An array of table data.
    */
   public function get($key = NULL) {
     if (!$key) {
+      @trigger_error('Calling get() without the $key argument is deprecated in drupal:8.2.0 and is required in drupal:9.0.0. See https://www.drupal.org/node/3090442', E_USER_DEPRECATED);
       return $this->getAll();
     }
     if (!isset($this->storage[$key])) {
@@ -297,7 +299,7 @@ protected function processEntityTypes(array &$data) {
   public function fetchBaseTables() {
     $tables = [];
 
-    foreach ($this->get() as $table => $info) {
+    foreach ($this->getAll() as $table => $info) {
       if (!empty($info['table']['base'])) {
         $tables[$table] = [
           'title' => $info['table']['base']['title'],
diff --git a/core/modules/views/src/ViewsDataHelper.php b/core/modules/views/src/ViewsDataHelper.php
index 6a9188bee681..da4f7f1c3b57 100644
--- a/core/modules/views/src/ViewsDataHelper.php
+++ b/core/modules/views/src/ViewsDataHelper.php
@@ -51,7 +51,7 @@ public function __construct(ViewsData $views_data) {
    */
   public function fetchFields($base, $type, $grouping = FALSE, $sub_type = NULL) {
     if (!$this->fields) {
-      $data = $this->data->get();
+      $data = $this->data->getAll();
       // This constructs this ginormous multi dimensional array to
       // collect the important data about fields. In the end,
       // the structure looks a bit like this (using nid as an example)
diff --git a/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php
index 3c3ed24e2acf..e08f01d67543 100644
--- a/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php
@@ -52,7 +52,7 @@ public function testHandlers() {
     $this->addDefaultCommentField('node', 'article');
 
     $object_types = array_keys(ViewExecutable::getHandlerTypes());
-    foreach ($this->container->get('views.views_data')->get() as $base_table => $info) {
+    foreach ($this->container->get('views.views_data')->getAll() as $base_table => $info) {
       if (!isset($info['table']['base'])) {
         continue;
       }
diff --git a/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php b/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php
index b08938c234e0..6dbfd3c94dda 100644
--- a/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php
+++ b/core/modules/views/tests/src/Unit/ViewsDataHelperTest.php
@@ -43,7 +43,7 @@ public function testFetchFields() {
       ->disableOriginalConstructor()
       ->getMock();
     $views_data->expects($this->once())
-      ->method('get')
+      ->method('getAll')
       ->will($this->returnValue($this->viewsData()));
 
     $data_helper = new ViewsDataHelper($views_data);
diff --git a/core/modules/views/tests/src/Unit/ViewsDataTest.php b/core/modules/views/tests/src/Unit/ViewsDataTest.php
index 4d0b6766b4a2..cd718c759f3c 100644
--- a/core/modules/views/tests/src/Unit/ViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/ViewsDataTest.php
@@ -642,6 +642,9 @@ public function testCacheCallsWithoutWarmCacheAndGetMultipleTables() {
    * logic.
    *
    * @covers ::getAll
+   * @group legacy
+   *
+   * @expectedDeprecation Calling get() without the $key argument is deprecated in drupal:8.2.0 and is required in drupal:9.0.0. See https://www.drupal.org/node/3090442
    */
   public function testGetAllEqualsToGetNull() {
     $expected_views_data = $this->viewsDataWithProvider();
-- 
GitLab