diff --git a/README.md b/README.md
index 6d2603b..04674a9 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,8 @@ An internal link might be helpful if you have a specific entry you want to easil
An external link might be helpful for a variety of different reasons. These should be provided as absolute URLs, complete with protocol (http/https).
+You can also set a custom icon for a menu item. This is uploaded to an existing assets source, and is recommended to be an SVG file for best results.
+
It should also be noted that some plugins already provide a method for changing the Plugin name. While Control Panel Nav is active, it's settings will override any defined in other installed plugins.
@@ -40,7 +42,6 @@ Craft Pro installs will be able to assign new layouts to user groups, while Craf
- Handle menu items with the same name, and handle generation.
- Support for sub-navigation.
-- Support for custom icons.
Have a suggestion? We'd love to hear about it! [Make a suggestion](https://github.com/engram-design/CPNav/issues)
diff --git a/changelog.json b/changelog.json
index 943d4e8..d89cf89 100644
--- a/changelog.json
+++ b/changelog.json
@@ -1,4 +1,13 @@
[
+ {
+ "version": "1.7.5",
+ "downloadUrl": "https://github.com/engram-design/CPNav/archive/1.7.5.zip",
+ "date": "2016-06-25T17:18:00+10:00",
+ "notes": [
+ "[Added] Added support for translations with menu labels.",
+ "[Added] Added ability to upload and set custom icons for menu items."
+ ]
+ },
{
"version": "1.7.4",
"downloadUrl": "https://github.com/engram-design/CPNav/archive/1.7.4.zip",
diff --git a/cpnav/CpNavPlugin.php b/cpnav/CpNavPlugin.php
index 50740e5..cf87404 100644
--- a/cpnav/CpNavPlugin.php
+++ b/cpnav/CpNavPlugin.php
@@ -14,12 +14,12 @@ public function getName()
public function getVersion()
{
- return '1.7.4';
+ return '1.7.5';
}
public function getSchemaVersion()
{
- return '1.0.0';
+ return '1.1.0';
}
public function getDeveloper()
diff --git a/cpnav/controllers/CpNav_NavController.php b/cpnav/controllers/CpNav_NavController.php
index 2702b02..c56cd87 100644
--- a/cpnav/controllers/CpNav_NavController.php
+++ b/cpnav/controllers/CpNav_NavController.php
@@ -74,15 +74,31 @@ public function actionGetHudHtml()
$nav->manualNav = true;
}
+ $criteria = craft()->elements->getCriteria(ElementType::Asset);
+ $criteria->id = false;
+ $criteria->status = null;
+ $criteria->localeEnabled = null;
+
+ if ($nav->customIcon) {
+ $criteria->id = array('7');
+ }
+
$variables = array(
'nav' => $nav,
+ 'sources' => craft()->assetSources->getAllSources(),
+ 'elements' => $criteria,
);
$template = craft()->request->getPost('template', 'cpnav/_includes/navigation-hud');
- $returnData['html'] = $this->renderTemplate($template, $variables, true);
+ craft()->templates->startJsBuffer();
+ $bodyHtml = $this->renderTemplate($template, $variables, true);
+ $footHtml = craft()->templates->clearJsBuffer();
- $this->returnJson($returnData);
+ $this->returnJson(array(
+ 'html' => $bodyHtml,
+ 'footerJs' => $footHtml,
+ ));
}
public function actionSave()
@@ -96,6 +112,7 @@ public function actionSave()
$nav->currLabel = craft()->request->getPost('currLabel');
$nav->url = craft()->request->getPost('url');
$nav->newWindow = craft()->request->getPost('newWindow');
+ $nav->customIcon = craft()->request->getPost('customIcon');
$nav = craft()->cpNav_nav->save($nav);
@@ -124,6 +141,7 @@ public function actionNew()
$nav->url = $url;
$nav->prevUrl = $url;
$nav->icon = null;
+ $nav->customIcon = null;
$nav->manualNav = true;
$nav->newWindow = $newWindow;
diff --git a/cpnav/migrations/m160625_000000_cpNav_addCustomIconSupport.php b/cpnav/migrations/m160625_000000_cpNav_addCustomIconSupport.php
new file mode 100644
index 0000000..95e6c80
--- /dev/null
+++ b/cpnav/migrations/m160625_000000_cpNav_addCustomIconSupport.php
@@ -0,0 +1,16 @@
+dbConnection->schema->getTable('{{cpnav_navs}}');
+
+ if ($navsTable->getColumn('customIcon') === null) {
+ $this->addColumnAfter('cpnav_navs', 'customIcon', array('column' => ColumnType::Text), 'icon');
+ }
+
+ return true;
+ }
+}
diff --git a/cpnav/models/CpNav_NavModel.php b/cpnav/models/CpNav_NavModel.php
index c04f9bb..c231cce 100644
--- a/cpnav/models/CpNav_NavModel.php
+++ b/cpnav/models/CpNav_NavModel.php
@@ -58,6 +58,7 @@ protected function defineAttributes()
'prevUrl' => array(AttributeType::String),
'url' => array(AttributeType::String),
'icon' => array(AttributeType::String),
+ 'customIcon' => array(AttributeType::Mixed),
'manualNav' => array(AttributeType::Bool),
'newWindow' => array(AttributeType::Bool),
diff --git a/cpnav/records/CpNav_NavRecord.php b/cpnav/records/CpNav_NavRecord.php
index da83626..2f11a9d 100644
--- a/cpnav/records/CpNav_NavRecord.php
+++ b/cpnav/records/CpNav_NavRecord.php
@@ -19,6 +19,7 @@ protected function defineAttributes()
'prevUrl' => array(AttributeType::String),
'url' => array(AttributeType::String),
'icon' => array(AttributeType::String),
+ 'customIcon' => array(AttributeType::String),
'manualNav' => array(AttributeType::Bool),
'newWindow' => array(AttributeType::Bool),
);
diff --git a/cpnav/resources/js/CPNavNavigation.js b/cpnav/resources/js/CPNavNavigation.js
index 77a4c4e..978deab 100644
--- a/cpnav/resources/js/CPNavNavigation.js
+++ b/cpnav/resources/js/CPNavNavigation.js
@@ -81,6 +81,8 @@ $(function() {
new Craft.HandleGenerator('#currLabel', '#handle');
+ Garnish.$bod.append(response.footerJs);
+
this.addListener($saveBtn, 'click', 'saveGroupField');
this.addListener($cancelBtn, 'click', 'closeHud');
}
@@ -247,6 +249,8 @@ $(function() {
this.hud.on('hide', $.proxy(this, 'closeHud'));
+ Garnish.$bod.append(response.footerJs);
+
this.addListener($saveBtn, 'click', 'saveGroupField');
this.addListener($cancelBtn, 'click', 'closeHud');
}
diff --git a/cpnav/services/CpNavService.php b/cpnav/services/CpNavService.php
index 25fa5b0..8193043 100644
--- a/cpnav/services/CpNavService.php
+++ b/cpnav/services/CpNavService.php
@@ -75,6 +75,21 @@ public function modifyCpNav(&$nav)
if ($newNav->craftIcon) {
$nav[$newNav->handle]['icon'] = $newNav->icon;
}
+
+ if ($newNav->customIcon) {
+ try {
+ $asset = craft()->assets->getFileById($newNav->customIcon);
+ $path = $asset->getSource()->settings['path'] . $asset->getFolder()->path . $asset->filename;
+
+ if (IOHelper::fileExists($path)) {
+ $iconSvg = IOHelper::getFileContents($path);
+ } else {
+ $iconSvg = false;
+ }
+
+ $nav[$newNav->handle]['iconSvg'] = $iconSvg;
+ } catch (\Exception $e) {}
+ }
}
}
}
diff --git a/cpnav/services/CpNav_NavService.php b/cpnav/services/CpNav_NavService.php
index 0cc64d1..e587097 100644
--- a/cpnav/services/CpNav_NavService.php
+++ b/cpnav/services/CpNav_NavService.php
@@ -53,6 +53,7 @@ public function save(CpNav_NavModel $model)
$record->url = $model->url;
$record->prevUrl = $model->prevUrl;
$record->icon = $model->icon;
+ $record->customIcon = $model->customIcon;
$record->manualNav = $model->manualNav;
$record->newWindow = $model->newWindow;
diff --git a/cpnav/templates/_includes/navigation-hud.html b/cpnav/templates/_includes/navigation-hud.html
index ed5effd..9c94aa5 100644
--- a/cpnav/templates/_includes/navigation-hud.html
+++ b/cpnav/templates/_includes/navigation-hud.html
@@ -37,6 +37,26 @@
}) }}
{% endif %}
+{% set elements = (elements is defined ? elements : []) -%}
+
+{{ forms.elementSelectField({
+ elements: elements,
+ id: 'customIcon',
+ name: 'customIcon',
+ label: 'Icon' | t,
+ instructions: 'Specify an SVG asset for this menu item icon.' | t,
+ elementType: craft.elements.getElementType('Asset'),
+ criteria: {
+ kind: [],
+ localeEnabled: null,
+ locale: null,
+ },
+ sources: sources,
+ jsClass: 'Craft.AssetSelectInput',
+ addButtonLabel: 'Select an Icon' |t,
+ limit: 1,
+}) }}
+