Skip to content

Commit

Permalink
Added link to element CP edit page from individual node
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromtheoutfit committed May 24, 2016
1 parent b11926a commit 0eaabcc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 27 deletions.
20 changes: 20 additions & 0 deletions controllers/Navee_NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ public function actionEditNode(array $variables = array())
$variables['entryElements'][] = craft()->entries->getEntryById($variables['node']->entryId);
$variables['assetElements'][] = craft()->assets->getFileById($variables['node']->assetId);
$variables['categoryElements'][] = craft()->categories->getCategoryById($variables['node']->categoryId);

// get a link to the element in the cp if it is an entry or category
switch ($variables['node']->linkType)
{
case 'entryId':
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->id = $variables['node']->entryId;
$entry = $criteria->first();
$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();
$variables['node']->linkedElementCpEditUrl = $entry->getCpEditUrl();
$variables['node']->linkedElementType = 'Category';
break;
}

}

if ($variables['navigation']->maxLevels != 1)
Expand Down
56 changes: 29 additions & 27 deletions models/Navee_NodeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@ class Navee_NodeModel extends BaseElementModel {
protected function defineAttributes()
{
return array_merge(parent::defineAttributes(), array(
'navigationId' => AttributeType::Number,
'linkType' => array(AttributeType::Enum, 'values' => ['entryId', 'assetId', 'categoryId', 'customUri', 'none']),
'entryId' => AttributeType::Number,
'assetId' => AttributeType::Number,
'categoryId' => AttributeType::Number,
'customUri' => array(AttributeType::String, 'default' => ''),
'class' => array(AttributeType::String, 'default' => ''),
'idAttr' => array(AttributeType::String, 'default' => ''),
'rel' => array(AttributeType::String, 'default' => ''),
'name' => array(AttributeType::String, 'default' => ''),
'titleAttr' => array(AttributeType::String, 'default' => ''),
'accessKey' => array(AttributeType::String, 'default' => ''),
'target' => array(AttributeType::String, 'default' => ''),
'includeInNavigation' => array(AttributeType::Bool, 'default' => true),
'passive' => array(AttributeType::Bool, 'default' => false),
'active' => array(AttributeType::Bool, 'default' => false),
'ancestorActive' => array(AttributeType::Bool, 'default' => false),
'descendantActive' => array(AttributeType::Bool, 'default' => false),
'entryEnabled' => array(AttributeType::Bool, 'default' => false),
'link' => array(AttributeType::String, 'default' => ''),
'text' => array(AttributeType::String, 'default' => ''),
'entryLink' => array(AttributeType::String, 'default' => ''),
'categoryLink' => array(AttributeType::String, 'default' => ''),
'newParentId' => AttributeType::Number,
'siblingActive' => array(AttributeType::Bool, 'default' => false),
'userGroups' => array(AttributeType::Mixed, 'default' => ''),
'navigationId' => AttributeType::Number,
'linkType' => array(AttributeType::Enum, 'values' => ['entryId', 'assetId', 'categoryId', 'customUri', 'none']),
'entryId' => AttributeType::Number,
'assetId' => AttributeType::Number,
'categoryId' => AttributeType::Number,
'customUri' => array(AttributeType::String, 'default' => ''),
'class' => array(AttributeType::String, 'default' => ''),
'idAttr' => array(AttributeType::String, 'default' => ''),
'rel' => array(AttributeType::String, 'default' => ''),
'name' => array(AttributeType::String, 'default' => ''),
'titleAttr' => array(AttributeType::String, 'default' => ''),
'accessKey' => array(AttributeType::String, 'default' => ''),
'target' => array(AttributeType::String, 'default' => ''),
'includeInNavigation' => array(AttributeType::Bool, 'default' => true),
'passive' => array(AttributeType::Bool, 'default' => false),
'active' => array(AttributeType::Bool, 'default' => false),
'ancestorActive' => array(AttributeType::Bool, 'default' => false),
'descendantActive' => array(AttributeType::Bool, 'default' => false),
'entryEnabled' => array(AttributeType::Bool, 'default' => false),
'link' => array(AttributeType::String, 'default' => ''),
'text' => array(AttributeType::String, 'default' => ''),
'entryLink' => array(AttributeType::String, 'default' => ''),
'categoryLink' => array(AttributeType::String, 'default' => ''),
'newParentId' => AttributeType::Number,
'siblingActive' => array(AttributeType::Bool, 'default' => false),
'userGroups' => array(AttributeType::Mixed, 'default' => ''),
'linkedElementCpEditUrl' => array(AttributeType::String, 'default' => ''),
'linkedElementType' => array(AttributeType::String, 'default' => ''),
));
}

Expand Down Expand Up @@ -68,7 +70,7 @@ public function getCpEditUrl()
return UrlHelper::getCpUrl('navee/node/' . $navigation->handle . '/' . $this->id);
}
}


/**
* Returns the field layout used by this element.
Expand Down
2 changes: 2 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"downloadUrl": "https://github.com/fromtheoutfit/navee/archive/master.zip",
"date": "2016-05-18T10:11:00-05:00",
"notes": [
"[Added] Link to elements edit page in the CP from the main navigations page.",
"[Added] Link to elements edit page in the CP from the individual node page.",
"[Added] Heads up display editor from navigation landing page now allows user to change node text as well as switch between different link types."
]
},
Expand Down
6 changes: 6 additions & 0 deletions templates/nodes/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ <h2>User Groups</h2>

{% if node.id %}
<div class="pane lightpane meta">
{% if node.linkedElementCpEditUrl %}
<div class="data">
<h5 class="heading">{{ "Element"|t }}</h5>
<div class="value"><a href="{{ node.linkedElementCpEditUrl }}">Edit {{ node.linkedElementType }}</a></div>
</div>
{% endif %}
<div class="data">
<h5 class="heading">{{ "Date Created"|t }}</h5>
<div class="value">{{ node.dateCreated.localeDate() }} {{ node.dateCreated.localeTime() }}</div>
Expand Down

0 comments on commit 0eaabcc

Please sign in to comment.