Add plugin hooks for assets
This commit is contained in:
@@ -10,6 +10,26 @@ namespace Helper;
|
|||||||
*/
|
*/
|
||||||
class Hook extends \Core\Base
|
class Hook extends \Core\Base
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Add assets JS or CSS
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $type
|
||||||
|
* @param string $hook
|
||||||
|
* @param array $variables
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function asset($type, $hook)
|
||||||
|
{
|
||||||
|
$buffer = '';
|
||||||
|
|
||||||
|
foreach ($this->hook->getListeners($hook) as $file) {
|
||||||
|
$buffer .= $this->helper->asset->$type($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render all attached hooks
|
* Render all attached hooks
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
<?= $this->asset->css('assets/css/print.css', true, 'print') ?>
|
<?= $this->asset->css('assets/css/print.css', true, 'print') ?>
|
||||||
<?= $this->asset->customCss() ?>
|
<?= $this->asset->customCss() ?>
|
||||||
|
|
||||||
|
<?= $this->hook->asset('css', 'template:layout:css') ?>
|
||||||
|
<?= $this->hook->asset('js', 'template:layout:js') ?>
|
||||||
|
|
||||||
<link rel="icon" type="image/png" href="<?= $this->url->dir() ?>assets/img/favicon.png">
|
<link rel="icon" type="image/png" href="<?= $this->url->dir() ?>assets/img/favicon.png">
|
||||||
<link rel="apple-touch-icon" href="<?= $this->url->dir() ?>assets/img/touch-icon-iphone.png">
|
<link rel="apple-touch-icon" href="<?= $this->url->dir() ?>assets/img/touch-icon-iphone.png">
|
||||||
<link rel="apple-touch-icon" sizes="72x72" href="<?= $this->url->dir() ?>assets/img/touch-icon-ipad.png">
|
<link rel="apple-touch-icon" sizes="72x72" href="<?= $this->url->dir() ?>assets/img/touch-icon-ipad.png">
|
||||||
|
|||||||
@@ -154,6 +154,34 @@ List of merge hooks:
|
|||||||
- `$start` Calendar start date (string, ISO-8601 format)
|
- `$start` Calendar start date (string, ISO-8601 format)
|
||||||
- `$end` Calendar end date (string, ISO-8601 format)
|
- `$end` Calendar end date (string, ISO-8601 format)
|
||||||
|
|
||||||
|
Asset Hooks
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Asset hooks can be used to add easily a new stylesheet or a new javascript file in the layout. You can use this feature to create a theme and override all Kanboard default styles.
|
||||||
|
|
||||||
|
Example to add a new stylesheet:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Plugin\Css;
|
||||||
|
|
||||||
|
use Core\Plugin\Base;
|
||||||
|
|
||||||
|
class Plugin extends Base
|
||||||
|
{
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
$this->hook->on('template:layout:css', 'plugins/Css/skin.css');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
List of asset Hooks:
|
||||||
|
|
||||||
|
- `template:layout:css`
|
||||||
|
- `template:layout:js`
|
||||||
|
|
||||||
Template hooks
|
Template hooks
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@@ -338,3 +366,4 @@ Examples of plugins
|
|||||||
- [User timetable](https://github.com/kanboard/plugin-timetable)
|
- [User timetable](https://github.com/kanboard/plugin-timetable)
|
||||||
- [Subtask Forecast](https://github.com/kanboard/plugin-subtask-forecast)
|
- [Subtask Forecast](https://github.com/kanboard/plugin-subtask-forecast)
|
||||||
- [Theme plugin sample](https://github.com/kanboard/plugin-example-theme)
|
- [Theme plugin sample](https://github.com/kanboard/plugin-example-theme)
|
||||||
|
- [CSS plugin sample](https://github.com/kanboard/plugin-example-css)
|
||||||
|
|||||||
@@ -37,4 +37,38 @@ class HookHelperTest extends Base
|
|||||||
$h->attach('test', 'tpl2');
|
$h->attach('test', 'tpl2');
|
||||||
$this->assertEquals('tpl1_contenttpl2_content', $h->render('test'));
|
$this->assertEquals('tpl1_contenttpl2_content', $h->render('test'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function testAssetHooks()
|
||||||
|
{
|
||||||
|
$this->container['helper']->asset = $this
|
||||||
|
->getMockBuilder('\Helper\Asset')
|
||||||
|
->setConstructorArgs(array($this->container))
|
||||||
|
->setMethods(array('css', 'js'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->container['helper']
|
||||||
|
->asset
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('css')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('skin.css')
|
||||||
|
)
|
||||||
|
->will($this->returnValue('<link rel="stylesheet" href="skin.css"></link>'));
|
||||||
|
|
||||||
|
$this->container['helper']
|
||||||
|
->asset
|
||||||
|
->expects($this->at(1))
|
||||||
|
->method('js')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('skin.js')
|
||||||
|
)
|
||||||
|
->will($this->returnValue('<script src="skin.js"></script>'));
|
||||||
|
|
||||||
|
$h = new Hook($this->container);
|
||||||
|
$h->attach('test1', 'skin.css');
|
||||||
|
$h->attach('test2', 'skin.js');
|
||||||
|
|
||||||
|
$this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $h->asset('css', 'test1'));
|
||||||
|
$this->assertContains('<script src="skin.js"></script>', $h->asset('js', 'test2'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user