whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

Extend Twitter Bootstrap #214

Open bogdaniel opened 7 years ago

bogdaniel commented 7 years ago

Hey guys, i'm new to fanta pager and i've been trying to extend the current functionality of twitter template to add data-attributes to the links. i was wondering is there a better way of doing this ?

class CustomFantaView extends TwitterBootstrap3Template
{

    public function page($page)
    {
        $text = $page;

        return $this->pageWithText($page, $text);
    }

    public function pageWithText($page, $text)
    {
        $class = null;

        return $this->pageWithTextAndClass($page, $text, $class);
    }

    private function pageWithTextAndClass($page, $text, $class)
    {
        $href = $this->generateRoute($page);

        return $this->linkLi($class, $href, $page, $text);
    }

    public function previousEnabled($page)
    {
        $text = $this->option('prev_message');
        $class = $this->option('css_prev_class');

        return $this->pageWithTextAndClass($page, $text, $class);
    }

    public function nextEnabled($page)
    {
        $text = $this->option('next_message');
        $class = $this->option('css_next_class');

        return $this->pageWithTextAndClass($page, $text, $class);
    }

    private function linkLi($class, $href, $text, $page)
    {
        $liClass = $class ? sprintf(' class="%s"', $class) : '';

        return sprintf('<li%s><a href="%s" data-page="%s">%s</a></li>', $liClass, $href, $text, $page);
    }
}
cezzre commented 7 years ago

Looks good to me. You don't need to override every method, though. Just the ones you want to customise.