function om_maximenu_links_order in OM Maximenu 7
Same name and namespace in other branches
- 8 inc/om_maximenu.admin.inc \om_maximenu_links_order()
- 6 inc/om_maximenu.admin.inc \om_maximenu_links_order()
OM Links
1 call to om_maximenu_links_order()
- _om_maximenu_admin in inc/
om_maximenu.admin.inc - Admin Form
File
- inc/
om_maximenu.admin.inc, line 573 - OM Maximenu Admin Configuration
Code
function om_maximenu_links_order($menu_content = array(), $roles = array(), $menu_key = 0) {
if (!isset($menu_content['links'])) {
$menu_content['links'] = array();
}
// This makes sure that even if existing links are deleted
// it won't have an id below the existing ones
// new link ids will depend on the highest existing link id;
$count = !empty($menu_content['links']) ? max(array_keys($menu_content['links'])) + 1 : 1;
// sort by weight
uasort($menu_content['links'], 'om_sort_by_weight');
$menu_content['links'] += _om_new_link($count, $roles);
$links = array();
foreach ($menu_content['links'] as $link => $prop) {
// count enabled blocks
$enabled_blocks = isset($prop['content']) && !empty($prop['content']) ? count($prop['content']) : 0;
// field description attached text
$attached = $enabled_blocks ? $enabled_blocks == 1 ? '@enabled_blocks block' : '@enabled_blocks blocks' : 'none';
$edit_attached = l(t('<strong>Edit</strong> attached blocks.'), 'admin/structure/om-maximenu/blocks/' . $menu_key . '/' . $link, array(
'attributes' => array(
'title' => t('Enable / Disabled blocks attached to this link.'),
),
'query' => drupal_get_destination(),
'html' => TRUE,
));
$new_message = t('You can only enable/disable blocks on this link after you have modified the link title and saved.');
$link_title = isset($prop['link_title']) && !empty($prop['link_title']) ? trim($prop['link_title']) : 'New Link';
// php on title
if (isset($prop['php_option']) && $prop['php_option'] == 1) {
ob_start();
$link_title = eval($prop['link_title']);
//$output = ob_get_contents();
ob_end_clean();
}
$links['menu_key'] = array(
'#type' => 'hidden',
'#default_value' => $menu_key,
);
$links[$link] = array(
'#type' => 'fieldset',
'#title' => t(om_string_name($link_title, FALSE)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => !empty($link_title) && $link_title != 'New Link' ? t('<strong>Attached:</strong> ' . $attached . '<br /><br />' . $edit_attached, array(
'@enabled_blocks' => $enabled_blocks,
)) : $new_message,
);
// delete field is only for existing links
if ($link_title != 'New Link') {
$links[$link]['link_delete'] = array(
'#type' => 'checkbox',
'#title' => t('Delete this link.'),
'#default_value' => 0,
);
}
$links[$link]['link_title'] = array(
'#type' => 'textarea',
'#title' => t('Link Title'),
'#rows' => 1,
'#required' => TRUE,
'#default_value' => isset($prop['link_title']) && !empty($prop['link_title']) ? stripslashes(trim($prop['link_title'])) : 'New Link',
'#description' => t('You can add inline styling or other attributes, ex. <span class="special-link" style="font-weight: bold;">Home</span>'),
);
$links[$link]['title_options'] = array(
'#type' => 'fieldset',
'#title' => t('Title Options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$links[$link]['title_options']['link_title_option'] = array(
'#type' => 'select',
'#title' => t('Options for Link Title'),
'#default_value' => isset($prop['link_title_option']) ? $prop['link_title_option'] : 'title',
'#options' => array(
'title' => 'Title only',
'title_icon' => 'Title with Icon',
'icon' => 'Icon only',
),
);
$links[$link]['title_options']['path_icon'] = array(
'#type' => 'textfield',
'#title' => t('Icon Path'),
'#default_value' => isset($prop['path_icon']) ? trim($prop['path_icon']) : '',
'#description' => t('
Ex. sites/default/themes/mytheme/css/images/icon_1.png or<br />
sites/default/files/icon_1.png <br />
(By default, this icon will go to the left side of the link title.). <br />
This can also be done via css properties, ex .link-home { background: url(...)...'),
);
$links[$link]['title_options']['icon_option'] = array(
'#type' => 'checkbox',
'#title' => t('Icon Hover Image'),
'#default_value' => isset($prop['icon_option']) ? $prop['icon_option'] : 0,
'#description' => t('You can have a mouseover icon, just upload another image, Ex. icon.png, icon_hover.png, <br />
just add "_hover" to the second image and this will automatically replace your active state icon on mouseover.'),
);
$links[$link]['title_options']['php_option'] = array(
'#type' => 'checkbox',
'#title' => t('Title has PHP'),
'#default_value' => isset($prop['php_option']) ? $prop['php_option'] : 0,
'#description' => t('DO NOT include <?php and ?>, always add a return value, <br />
ex. <strong> global $user; return \'<strong>\' . $user->name . \'</strong>\';</strong>",<br />
make sure your code is valid php, any error on this can potentially break your site.'),
);
$links[$link]['path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#default_value' => isset($prop['path']) ? trim($prop['path']) : '',
'#autocomplete_path' => module_exists('mpac') ? 'mpac/autocomplete' : '',
'#description' => t('
<ul>
<li><strong>Front Page</strong> - put <front> as path.</li>
<li><strong>No Link</strong> - empty path is valid and will transform "a" tag to "span" tag.</li>
</ul>
'),
);
$links[$link]['path_query'] = array(
'#type' => 'textfield',
'#title' => t('Path Query'),
'#default_value' => isset($prop['path_query']) ? trim($prop['path_query']) : array(),
'#description' => t('Ex. ?destination=node&me=you, but DO NOT include \'?\'.'),
);
$links[$link]['path_fragment'] = array(
'#type' => 'textfield',
'#title' => t('Anchor'),
'#default_value' => isset($prop['path_fragment']) ? trim($prop['path_fragment']) : '',
'#description' => t('Ex. #section-1, but DO NOT include \'#\'. This can correspond to the id name of a tag, ex. <div id="section-1",<br />
so you can now target this section by doing "about#section-1", and the page will automatically scroll to that section.'),
);
$links[$link]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#attributes' => array(
'class' => array(
'om-weight',
),
),
'#default_value' => isset($prop['weight']) ? $prop['weight'] : 0,
'#description' => t('Negative values have the highest position in the order, so -1 comes first before 0 then 1, ...'),
);
$links[$link]['attributes'] = array(
'#type' => 'fieldset',
'#title' => t('Link Attributes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$links[$link]['attributes']['id'] = array(
'#type' => 'textfield',
'#title' => t('ID'),
'#default_value' => isset($prop['id']) ? trim($prop['id']) : '',
'#description' => t('Make sure this ID is unique.'),
);
$links[$link]['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Classes'),
'#default_value' => isset($prop['class']) ? trim($prop['class']) : '',
'#description' => t('It\'s a good practice to have classes in lowercase and dashes separating words.'),
);
$links[$link]['attributes']['rel'] = array(
'#type' => 'textfield',
'#title' => t('Relationship'),
'#default_value' => isset($prop['rel']) ? trim($prop['rel']) : '',
'#description' => t('
<ul>
<li><strong>nofollow</strong> - for search engines not to follow the link.</li>
<li><strong>lightbox</strong> - if you installed Lighbox 2, see your other options on Lightbox 2 README.txt.</li>
<li>Other modules may have uses for this, so I just kept it as textfield.</li>
</ul>
'),
);
$links[$link]['attributes']['target'] = array(
'#type' => 'select',
'#title' => t('Target Window'),
'#options' => array(
'_self' => 'Self',
'_blank' => 'Blank',
'_parent' => 'Parent',
'_top' => 'Top',
),
'#default_value' => isset($prop['target']) ? $prop['target'] : '_self',
);
$links[$link]['attributes']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => isset($prop['description']) ? $prop['description'] : '',
'#description' => t('Link additional information'),
);
$links[$link]['attributes']['description_option'] = array(
'#type' => 'select',
'#title' => t('Options for description'),
'#options' => array(
'hover' => 'Hover',
'subtitle' => 'Subtitle',
),
'#default_value' => isset($prop['description_option']) ? $prop['description_option'] : 'hover',
'#description' => t('
<ul>
<li><strong>Hover</strong> - appears on mouse over the link.</li>
<li><strong>Subtitle</strong> - appears as text under the link.</a>.</li>
</ul>
'),
);
$links[$link]['permission'] = array(
'#type' => 'fieldset',
'#title' => t('Permission'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$links[$link]['permission']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('User Roles'),
'#options' => $roles,
'#default_value' => isset($prop['roles']) ? $prop['roles'] : array(),
'#description' => t('If none is checked, this link will appear for all users.'),
);
//dsm($prop['content']);
// these are the blocks
if (isset($prop['content']) && is_array($prop['content'])) {
foreach ($prop['content'] as $block => $block_prop) {
foreach ($block_prop as $block_key => $block_val) {
$links[$link]['content'][$block][$block_key] = array(
'#type' => 'hidden',
'#default_value' => isset($block_val) ? trim($block_val) : '',
);
}
}
}
}
return $links;
}