Skip to content

Commit

Permalink
Regular Expression Field + Tabbed Edit Node
Browse files Browse the repository at this point in the history
[Added] New Regular Expression field allowing you to match dynamic URIs that do not exist in your navigation.
[Added] Tabbed layout - moving Attributes, Advanced and all custom field layouts into their own tabs.
  • Loading branch information
michaelfromtheoutfit committed Sep 23, 2016
1 parent b96db9e commit 0338619
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 162 deletions.
2 changes: 1 addition & 1 deletion NaveePlugin.php
Expand Up @@ -10,7 +10,7 @@ public function getName()

public function getVersion()
{
return '1.0.9';
return '1.1.0';
}

public function getDeveloper()
Expand Down
16 changes: 9 additions & 7 deletions controllers/Navee_NodeController.php
Expand Up @@ -133,20 +133,21 @@ public function actionEditNode(array $variables = array())
switch ($variables['node']->linkType)
{
case 'entryId':
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->id = $variables['node']->entryId;
$entry = $criteria->first();
if ($entry) {
$entry = $criteria->first();
if ($entry)
{
$variables['node']->linkedElementCpEditUrl = $entry->getCpEditUrl();
}
$variables['node']->linkedElementType = 'Entry';
break;
case 'categoryId':
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $variables['node']->categoryId;
$entry = $criteria->first();
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $variables['node']->categoryId;
$entry = $criteria->first();
$variables['node']->linkedElementCpEditUrl = $entry->getCpEditUrl();
$variables['node']->linkedElementType = 'Category';
$variables['node']->linkedElementType = 'Category';
break;
}

Expand Down Expand Up @@ -254,6 +255,7 @@ public function actionSaveNode()
$node->name = (craft()->request->getPost('name')) ? craft()->request->getPost('name') : '';
$node->titleAttr = (craft()->request->getPost('titleAttr')) ? craft()->request->getPost('titleAttr') : '';
$node->accessKey = (craft()->request->getPost('accessKey')) ? craft()->request->getPost('accessKey') : '';
$node->regex = (craft()->request->getPost('regex')) ? craft()->request->getPost('regex') : '';
$node->target = (craft()->request->getPost('target')) ? craft()->request->getPost('target') : '';
$node->includeInNavigation = (craft()->request->getPost('includeInNavigation')) ? craft()->request->getPost('includeInNavigation') : false;
$node->passive = (craft()->request->getPost('passive')) ? craft()->request->getPost('passive') : false;
Expand Down
57 changes: 57 additions & 0 deletions migrations/m160922_150924_navee_AddRegexField.php
@@ -0,0 +1,57 @@
<?php
namespace Craft;

/**
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName
*/
class m160922_150924_navee_AddRegexField extends BaseMigration {

/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
// specify columns and AttributeType
$newColumns = array(
'regex' => ColumnType::Varchar,
);

$this->_addColumnsAfter('navee_nodes', $newColumns, 'target');

// return true and let craft know its done
return true;
}

private function _addColumnsAfter($tableName, $newColumns, $afterColumnHandle)
{

// this is a foreach loop, enough said
foreach ($newColumns as $columnName => $columnType)
{
// check if the column does NOT exist
if (!craft()->db->columnExists($tableName, $columnName))
{
$this->addColumnAfter($tableName, $columnName, array(
'column' => $columnType,
'null' => false,
),
$afterColumnHandle
);

// log that we created the new column
SeomaticPlugin::log("Created the `$columnName` in the `$tableName` table.", LogLevel::Info, true);

}

// if the column already exists in the table
else {

// tell craft that we couldn't create the column as it alredy exists.
SeomaticPlugin::log("Column `$columnName` already exists in the `$tableName` table.", LogLevel::Info, true);

}
}
}
}
2 changes: 2 additions & 0 deletions models/Navee_NodeModel.php
Expand Up @@ -43,6 +43,7 @@ protected function defineAttributes()
'userGroups' => array(AttributeType::Mixed, 'default' => ''),
'linkedElementCpEditUrl' => array(AttributeType::String, 'default' => ''),
'linkedElementType' => array(AttributeType::String, 'default' => ''),
'regex' => array(AttributeType::String, 'default' => ''),
));
}

Expand Down Expand Up @@ -134,6 +135,7 @@ public function getDescendants($dist = null)
{
craft()->navee->setLink($d);
}

return $descendants;
}
}
1 change: 1 addition & 0 deletions records/Navee_NodeRecord.php
Expand Up @@ -36,6 +36,7 @@ protected function defineAttributes()
'includeInNavigation' => array(AttributeType::Bool, 'required' => true),
'passive' => array(AttributeType::Bool, 'required' => true),
'userGroups' => array(AttributeType::Mixed, 'required' => false),
'regex' => array(AttributeType::String, 'required' => false),
);
}

Expand Down
9 changes: 9 additions & 0 deletions releases.json
@@ -1,4 +1,13 @@
[
{
"version": "1.1.0",
"downloadUrl": "https://github.com/fromtheoutfit/navee/archive/v1.1.0.zip",
"date": "2016-09-23T10:23:00-05:00",
"notes": [
"[Added] New Regular Expression field allowing you to match dynamic URIs that do not exist in your navigation.",
"[Added] Tabbed layout - moving Attributes, Advanced and all custom field layouts into their own tabs."
]
},
{
"version": "1.0.9",
"downloadUrl": "https://github.com/fromtheoutfit/navee/archive/v1.0.9.zip",
Expand Down
31 changes: 28 additions & 3 deletions services/NaveeService.php
Expand Up @@ -158,10 +158,35 @@ private function nodeActive(Navee_NodeModel $node)
$currentUri = ltrim(craft()->request->getPath(), '/');
$link = ltrim($node->link, '/');

if (($link == $currentUri) && !$node->passive)
if (!$node->passive)
{
$node->active = true;
$data = true;
if ($link == $currentUri || $this->nodeActiveRegex($node, $currentUri))
{
$node->active = true;
$data = true;
}
}


return $data;
}

/**
* Checks to see if a node regex matches the current URI
*
* @access private
* @param Navee_NodeModel $node
* @param string $currentUri
* @return boolean
*/

private function nodeActiveRegex(Navee_NodeModel $node, $currentUri)
{
$data = false;

if (strlen($node->regex) && preg_match($node->regex, $currentUri))
{
$data = true;
}

return $data;
Expand Down
1 change: 1 addition & 0 deletions services/Navee_NodeService.php
Expand Up @@ -80,6 +80,7 @@ public function saveNode(Navee_NodeModel $node)
$nodeRecord->name = $node->name;
$nodeRecord->titleAttr = $node->titleAttr;
$nodeRecord->accessKey = $node->accessKey;
$nodeRecord->regex = $node->regex;
$nodeRecord->target = $node->target;
$nodeRecord->includeInNavigation = $node->includeInNavigation;
$nodeRecord->passive = $node->passive;
Expand Down

0 comments on commit 0338619

Please sign in to comment.