Skip to content

Commit

Permalink
Merge branch 'release/1.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 27, 2022
2 parents 9f3b0e8 + 82e3800 commit 5220db0
Show file tree
Hide file tree
Showing 17 changed files with 696 additions and 56 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v1.4.3
## 08/26/2022

1. [](#new)
* Pass phpstan level 1 tests
* Require Grav v1.6
* Moved pagination classes under `Grav\Plugin\Pagination` namespace
* Removed extension to bring Twig function into Plugin class

# v1.4.2
## 05/09/2019

Expand Down
6 changes: 5 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Pagination
version: 1.4.2
slug: pagination
type: plugin
version: 1.4.3
description: "**Pagination** is a very useful plugin to help navigate a large collection of pages, such as for a **blog**."
icon: list-ol
author:
Expand All @@ -10,6 +12,8 @@ homepage: https://github.com/getgrav/grav-plugin-pagination
keywords: pagination, plugin, pages, navigation
bugs: https://github.com/getgrav/grav-plugin-pagination/issues
license: MIT
dependencies:
- { name: grav, version: '>=1.6.0' }

form:
validation: strict
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Grav\Plugin;
namespace Grav\Plugin\Pagination;

use Grav\Common\Grav;
use Grav\Common\Iterator;
Expand All @@ -23,8 +23,6 @@ public function __construct(Collection $collection)
{
parent::__construct();

require_once __DIR__ . '/paginationpage.php';

$grav = Grav::instance();

/** @var Uri $uri */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Grav\Plugin;
namespace Grav\Plugin\Pagination;

use Grav\Common\Grav;

Expand Down
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "grav-plugin-pagination",
"type": "grav-plugin",
"description": "Pagination plugin for Grav CMS",
"keywords": ["pagination"],
"homepage": "https://github.com/getgrav/grav-plugin-pagination/",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "[email protected]",
"homepage": "http://getgrav.org",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Pagination\\": "classes/plugin"
},
"classmap": ["pagination.php"]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
24 changes: 24 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 33 additions & 9 deletions pagination.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php
namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Page\Collection;
use Grav\Common\Page\Page;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Plugin;
use Grav\Plugin\Pagination\PaginationHelper;
use Grav\Plugin\Pagination\PaginationPage;
use RocketTheme\Toolbox\Event\Event;
use Twig\TwigFunction;

class PaginationPlugin extends Plugin
{
Expand All @@ -19,10 +23,23 @@ class PaginationPlugin extends Plugin
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
'onPluginsInitialized' => [
['autoload', 100001],
['onPluginsInitialized', 0]
]
];
}

/**
* [onPluginsInitialized:100000] Composer autoload.
*
* @return ClassLoader
*/
public function autoload()
{
return require __DIR__ . '/vendor/autoload.php';
}

/**
* Initialize configuration
*/
Expand All @@ -33,6 +50,9 @@ public function onPluginsInitialized()
return;
}

class_alias(PaginationHelper::class, 'Grav\\Plugin\\PaginationHelper');
class_alias(PaginationPage::class, 'Grav\\Plugin\\PaginationPage');

$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPageInitialized' => ['onPageInitialized', 0],
Expand All @@ -53,17 +73,18 @@ public function onTwigTemplatePaths()
*/
public function onTwigExtensions()
{
require_once(__DIR__.'/twig/PaginationTwigExtension.php');

$this->grav['twig']->twig->addExtension(new PaginationTwigExtension());
// Add Twig functions
$this->grav['twig']->twig()->addFunction(
new TwigFunction('paginate', [$this, 'paginateTwigFunction'])
);
}

/**
* Enable pagination if page has params.pagination = true.
*/
public function onPageInitialized()
{
/** @var Page $page */
/** @var PageInterface $page */
$page = $this->grav['page'];

if ($page && ($page->value('header.content.pagination') || $page->value('header.pagination'))) {
Expand Down Expand Up @@ -96,7 +117,6 @@ public function onCollectionProcessed(Event $event)
}

if (!empty($params['limit']) && $collection->count() > $params['limit']) {
require_once __DIR__ . '/classes/paginationhelper.php';
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);
}
Expand All @@ -119,14 +139,13 @@ public function onTwigSiteVariables()
* @param int $limit
* @param array $ignore_param_array url parameters to be ignored in page links
*/
public function paginateCollection( $collection, $limit, $ignore_param_array = [])
public function paginateCollection($collection, $limit, $ignore_param_array = [])
{
$collection->setParams(['pagination' => 'true']);
$collection->setParams(['limit' => $limit]);
$collection->setParams(['ignore_params' => $ignore_param_array]);

if ($collection->count() > $limit) {
require_once __DIR__ . '/classes/paginationhelper.php';
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);

Expand All @@ -138,4 +157,9 @@ public function paginateCollection( $collection, $limit, $ignore_param_array = [
}
}
}

public function paginateTwigFunction($collection, $limit, $ignore_url_param_array = [])
{
$this->paginateCollection($collection, $limit, $ignore_url_param_array);
}
}
42 changes: 0 additions & 42 deletions twig/PaginationTwigExtension.php

This file was deleted.

7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87::getLoader();
Loading

0 comments on commit 5220db0

Please sign in to comment.