Added various ways to get and set the css/js/collections . This should allow full control of manipulating assets via plugins. #876

This commit is contained in:
Andy Miller
2016-06-02 18:05:24 -06:00
parent 858fbbe41c
commit ef456888f8
2 changed files with 84 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
# v1.1.0-rc.2
## xx/xx/2016
1. [](#new)
* Added getters and setters for Assets to allow manipulation of CSS/JS/Collection based assets via plugins [#876](https://github.com/getgrav/grav/issues/876)
1. [](#improved)
* Moved list items in `system/config/media.yaml` config into a `types:` key which allows you delete default items.

View File

@@ -821,24 +821,94 @@ class Assets
/**
* Return the array of all the registered CSS assets
* If a $key is provided, it will try to return only that asset
* else it will return null
*
* @param null|string $key the asset key
* @return array
*/
public function getCss()
public function getCss($key = null)
{
if (!empty($key)) {
$asset_key = md5($key);
if (isset($this->css[$asset_key])) {
return $this->css[$asset_key];
} else {
return null;
}
}
return $this->css;
}
/**
* Return the array of all the registered JS assets
* If a $key is provided, it will try to return only that asset
* else it will return null
*
* @param null|string $key the asset key
* @return array
*/
public function getJs()
public function getJs($key = null)
{
if (!empty($key)) {
$asset_key = md5($key);
if (isset($this->js[$asset_key])) {
return $this->js[$asset_key];
} else {
return null;
}
}
return $this->js;
}
/**
* Set the whole array of CSS assets
*
* @param $css
*/
public function setCss($css)
{
$this->css = $css;
}
/**
* Set the whole array of JS assets
*
* @param $js
*/
public function setJs($js)
{
$this->js = $js;
}
/**
* Removes an item from the CSS array if set
*
* @param $key the asset key
*/
public function removeCss($key)
{
$asset_key = md5($key);
if (isset($this->css[$asset_key])) {
unset($this->css[$asset_key]);
}
}
/**
* Removes an item from the JS array if set
*
* @param $key the asset key
*/
public function removeJs($key)
{
$asset_key = md5($key);
if (isset($this->js[$asset_key])) {
unset($this->js[$asset_key]);
}
}
/**
* Return the array of all the registered collections
*
@@ -849,6 +919,16 @@ class Assets
return $this->collections;
}
/**
* Set the array of collections explicitly
*
* @param $collections
*/
public function setCollection($collections)
{
$this->collections = $collections;
}
/**
* Determines if an asset exists as a collection, CSS or JS reference
*