CakePHP-Bootstrap / cakephp3-bootstrap-helpers

CakePHP 3.x Helpers for Bootstrap 3 and 4.
https://holt59.github.io/cakephp3-bootstrap-helpers/
MIT License
130 stars 79 forks source link

Add configurable defaults for BootstrapPaginatorHelper #130

Open Antoniossss opened 7 years ago

Antoniossss commented 7 years ago

For example, I would like to globally apply following configuration so it would be to every invokation of BootstrapPaginatorhelper#numbers()

                     [
                        "size" => "small",
                        "prev" => "<",
                        "next" => ">",
                        "ellipsis" => true,
                        "first"=>"first",
                        "last"=>"last",
                    ]

Right now I have to put those options to every invocation am I correct? It would be great to have ability to confiugre those values as defaults.

I think that perfect fit would be upon helper initialization

        'Paginator' => [
            'className' => 'Bootstrap.BootstrapPaginator',
            'numbers' => [
                "size" => "small",
                "prev" => "<",
                "next" => ">",
                "ellipsis" => true,
                "first" => "first",
                "last" => "last",
            ]
        ],

And after quick glance at the source, I found out that its is all about adding 2 lines

      if ($this->getConfig("numbers")) {
            $options += $this->getConfig("numbers");
        }

at the beginning of numbers method. Clean code and handy solution.

Holt59 commented 7 years ago

Easiest way to do this is to create your own helper and override numbers:

namespace App\View\Helper;

class MyPaginatorHelper extends \Bootstrap\View\Helper\PaginatorHelper {

    public function numbers(array $options = []) {
        $options += [
            "size" => "small",
            "prev" => "<",
            "next" => ">",
            "ellipsis" => true,
            "first" => "first",
            "last" => "last",
        ];
        return parent::numbers($options);
    }

}