NAP Toolbar Interface
With the introduction of a more centralized toolbar handling, the possibility to integrate toolbar data into NAP has been added. It allows a component to "register" toolbar buttons within their node and leaf data, which will then be merged into a full toolbar on demand.
Component integration
It is actually quite easy. You add toolbar-items, indexed by an integer (lowest number left in the resulting toolbar) into an array that is passed to NAP using the key MIDCOM_NAV_TOOLBAR. All URLs you add into these arrays are treated as relative to the AIS anchor prefix you would have (to your content topic).
This is an excerpt from the current taviwere code:
Node data:
// Create Toolbar
$toolbar[0] = Array
(
MIDCOM_TOOLBAR_URL => '',
MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create article'),
MIDCOM_TOOLBAR_HELPTEXT => null,
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_new.png',
MIDCOM_TOOLBAR_ENABLED => true
);
$toolbar[100] = Array
(
MIDCOM_TOOLBAR_URL => 'config.html',
MIDCOM_TOOLBAR_LABEL =>
$this->_l10n_midcom->get('component configuration'),
MIDCOM_TOOLBAR_HELPTEXT =>
$this->_l10n_midcom->get('component configuration helptext'),
MIDCOM_TOOLBAR_ICON =>
'stock-icons/16x16/stock_folder-properties.png',
MIDCOM_TOOLBAR_ENABLED => true
);
Leaf data:
if ($articles = mgd_list_topic_articles($topic->id, "score"))
{
// Prep toolbar
$toolbar[50] = Array(
MIDCOM_TOOLBAR_URL => '',
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('edit'),
MIDCOM_TOOLBAR_HELPTEXT => null,
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png',
MIDCOM_TOOLBAR_ENABLED => true
);
$toolbar[51] = Array(
MIDCOM_TOOLBAR_URL => '',
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('delete'),
MIDCOM_TOOLBAR_HELPTEXT => null,
MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png',
MIDCOM_TOOLBAR_ENABLED => true
);
$toolbar[52] = Array(
MIDCOM_TOOLBAR_URL => '',
MIDCOM_TOOLBAR_LABEL => '',
MIDCOM_TOOLBAR_HELPTEXT => null,
MIDCOM_TOOLBAR_ICON => '',
MIDCOM_TOOLBAR_ENABLED => true
);
while ($articles->fetch ()) {
// Match the toolbar to the correct URL.
$toolbar[50][MIDCOM_TOOLBAR_URL] =
"edit/{$articles->id}.html";
$toolbar[51][MIDCOM_TOOLBAR_URL] =
"delete/{$articles->id}.html";
$toolbar[52][MIDCOM_TOOLBAR_URL] =
"approve/{$articles->id}.html";
$toolbar[52][MIDCOM_TOOLBAR_LABEL] =
$articles->approved ? $this->_l10n->get('unapprove')
: $this->_l10n->get('approve');
$toolbar[52][MIDCOM_TOOLBAR_ICON] =
'stock-icons/16x16/' . ($articles->approved ?
'approved.png' : 'not_approved.png');
...
}
}
In both cases, $toolbar is added to the resulting NAP array.
Site integration
On-site, you can use the helper functions built into midcom_helper_nav (see the docs of the *toolbar functions) in that class. A simple, but not really useful example that shows all available toolbars looks like this:
3: <?php
4: $nap = new midcom_helper_nav();
5: $baseurl = 'https://atlantis.nehmer.net/admin/';
6: ?>
7:
8: <h3>Node Toolbar</h3>
9: <?php
10: echo $nap->render_node_toolbar($baseurl);
11: ?>
12:
13: <h3>Leaf Toolbar</h3>
14: <?php
15: $toolbar = $nap->render_leaf_toolbar($baseurl);
16: if (is_null($toolbar)) {
17: ?>
18: NO CURRENT LEAF SET
19: <?php
20: } else {
21: echo $toolbar;
22: }
23: ?>
24:
25: <h3>Combined Toolbar</h3>
26: <?php
27: echo $nap->render_combined_toolbar($baseurl);
28: ?>
29:
30: <h3>Combined Toolbar w/o style</h3>
31: <?php
32: $toolbar = $nap->get_combined_toolbar($baseurl);
33: $toolbar->class_style = null;
34: echo $toolbar->render();
35: ?>
It has yet to be discussed, how midcom-template will use this feature. Just in case you are curious, the above example roughly looks like this: