Browse Source

add deprecationWarning to PaginatorHelper::generateUrl()

saeid 7 years ago
parent
commit
9f2a773cf0

+ 12 - 4
src/View/Helper/PaginatorHelper.php

@@ -495,6 +495,7 @@ class PaginatorHelper extends Helper
      * @param array $options Pagination/URL options array
      * @param string|null $model Which model to paginate on
      * @param array|bool $urlOptions Array of options or bool `fullBase` for BC reasons.
+     * The bool version of this argument is *deprecated* and will be removed in 4.0.0
      * @return string By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
      * @link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#generating-pagination-urls
      */
@@ -502,6 +503,13 @@ class PaginatorHelper extends Helper
     {
         if (!is_array($urlOptions)) {
             $urlOptions = ['fullBase' => $urlOptions];
+            if (func_num_args() == 3) {
+                deprecationWarning(
+                    'Passing an bool as third argument into PaginatorHelper::generateUrl() is deprecated ' .
+                    'and will be removed in 4.0.0 . ' .
+                    'Pass an array instead.'
+                );
+            }
         }
         $urlOptions += [
             'escape' => true,
@@ -1150,19 +1158,19 @@ class PaginatorHelper extends Helper
         $links = [];
 
         if ($options['prev'] && $this->hasPrev()) {
-            $links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, true));
+            $links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, ['fullBase' => true]));
         }
 
         if ($options['next'] && $this->hasNext()) {
-            $links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, true));
+            $links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, ['fullBase' => true]));
         }
 
         if ($options['first']) {
-            $links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, true));
+            $links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, ['fullBase' => true]));
         }
 
         if ($options['last']) {
-            $links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, true));
+            $links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, ['fullBase' => true]));
         }
 
         $out = implode($links);

+ 6 - 4
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -804,10 +804,12 @@ class PaginatorHelperTest extends TestCase
         $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
 
         // @deprecated 3.3.5 Use fullBase array option instead.
-        $this->Paginator->request = $this->Paginator->request->withParam('paging.Article.page', 3);
-        $options = ['sort' => 'Article.name', 'direction' => 'desc'];
-        $result = $this->Paginator->generateUrl($options, null, true);
-        $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
+        $this->deprecated(function () {
+            $this->Paginator->request = $this->Paginator->request->withParam('paging.Article.page', 3);
+            $options = ['sort' => 'Article.name', 'direction' => 'desc'];
+            $result = $this->Paginator->generateUrl($options, null, true);
+            $this->assertEquals('http://localhost/index?page=3&sort=Article.name&direction=desc', $result);
+        });
     }
 
     /**