Skip to content

Commit

Permalink
version 1.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jun 24, 2016
1 parent 8b616ad commit 457ad8a
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand All @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cpnav/CpNavPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 20 additions & 2 deletions cpnav/controllers/CpNav_NavController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions cpnav/migrations/m160625_000000_cpNav_addCustomIconSupport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Craft;

class m160625_000000_cpNav_addCustomIconSupport extends BaseMigration
{
public function safeUp()
{
$navsTable = $this->dbConnection->schema->getTable('{{cpnav_navs}}');

if ($navsTable->getColumn('customIcon') === null) {
$this->addColumnAfter('cpnav_navs', 'customIcon', array('column' => ColumnType::Text), 'icon');
}

return true;
}
}
1 change: 1 addition & 0 deletions cpnav/models/CpNav_NavModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
1 change: 1 addition & 0 deletions cpnav/records/CpNav_NavRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
4 changes: 4 additions & 0 deletions cpnav/resources/js/CPNavNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down
15 changes: 15 additions & 0 deletions cpnav/services/CpNavService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cpnav/services/CpNav_NavService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions cpnav/templates/_includes/navigation-hud.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) }}

<input type="hidden" name="layoutId" value="{{ nav.layoutId }}" style="display: none;" />
<input type="hidden" name="id" value="{{ nav.id }}" style="display: none;" />
<input type="hidden" id="handle" name="handle" value="{{ nav.handle }}" style="display: none;" />
Expand Down

0 comments on commit 457ad8a

Please sign in to comment.