Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
valencia
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
9
Issues
9
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
valencia
Commits
56832962
Commit
56832962
authored
Jun 02, 2014
by
Riccardo Padovani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create function to generate subheader
parent
8e3dc772
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
3 deletions
+76
-3
template.php
template.php
+72
-0
tpl/page.tpl.php
tpl/page.tpl.php
+4
-3
No files found.
template.php
View file @
56832962
...
...
@@ -116,11 +116,50 @@ function valencia_preprocess_html( &$variables ) {
function
valencia_preprocess_page
(
&
$vars
)
{
// Get the entire main menu tree
$main_menu_tree
=
menu_tree_all_data
(
'main-menu'
);
// and add the active trail
menu_tree_add_active_path
(
$main_menu_tree
);
// Add the rendered output to menu
$vars
[
'valencia_menu'
]
=
menu_tree_output
(
$main_menu_tree
);
}
/**
* Add the active trail indicators into the tree.
*
* The data returned by menu_tree_page_data() has link['in_active_trail'] set
* to TRUE for each menu item in the active trail. The data returned from
* menu_tree_all_data() does not contain the active trail indicators. This is a
* helper function that adds it back in.
*
* Source:
* http://drupalcontrib.org/api/drupal/contributions!menu_block!menu_block.module/function/menu_tree_add_active_path/7
*/
function
menu_tree_add_active_path
(
&
$tree
)
{
// Grab any menu item to find the menu_name for this tree.
$menu_item
=
current
(
$tree
);
$tree_with_trail
=
menu_tree_page_data
(
$menu_item
[
'link'
][
'menu_name'
]);
// To traverse the original tree down the active trail, we use a pointer.
$subtree_pointer
=
&
$tree
;
// Find each key in the active trail.
while
(
$tree_with_trail
)
{
foreach
(
$tree_with_trail
as
$key
=>
&
$value
)
{
if
(
$tree_with_trail
[
$key
][
'link'
][
'in_active_trail'
])
{
// Set the active trail info in the original tree.
$subtree_pointer
[
$key
][
'link'
][
'in_active_trail'
]
=
TRUE
;
// Continue in the subtree, if it exists.
$tree_with_trail
=
&
$tree_with_trail
[
$key
][
'below'
];
$subtree_pointer
=
&
$subtree_pointer
[
$key
][
'below'
];
break
;
}
else
{
unset
(
$tree_with_trail
[
$key
]);
}
}
}
}
/**
* Choose which menu create basing on the id
*/
...
...
@@ -128,6 +167,8 @@ function valencia_links__system_main_menu($vars) {
switch
(
$vars
[
'id'
])
{
case
'header'
:
return
valencia_header_menu
(
$vars
);
case
'subheader'
:
return
valencia_subheader_menu
(
$vars
);
case
'footer'
:
return
valencia_footer_menu
(
$vars
);
}
...
...
@@ -154,6 +195,37 @@ function valencia_header_menu($vars) {
return
$html
;
}
/**
* Custom links for subheader menu
* Follows a custom design
*
* We need to print only the submenu of active menu
*/
function
valencia_subheader_menu
(
$vars
)
{
// Var with all HTML of the menu
$html
=
'<ul>'
;
foreach
(
$vars
[
'links'
]
as
$key
=>
$link
)
{
// To print every menu voice only one, see Drupal API
if
(
is_numeric
(
$key
))
{
// Check for submenu, but only if they are of first level and this
// is the active link
if
(
!
empty
(
$link
[
'#below'
])
&&
$link
[
'#original_link'
][
'depth'
]
===
'1'
&&
$link
[
'#original_link'
][
'in_active_trail'
])
{
// If there is a submenu create it using the header function,
// because they have the same struct
$sub_menu
=
theme
(
'links__system_main_menu'
,
array
(
'links'
=>
$link
[
'#below'
],
'id'
=>
'header'
));
$html
.=
$sub_menu
;
}
}
}
$html
.=
'</ul>'
;
return
$html
;
}
/**
* Custom links for footer menu
* Follows http://design.ubuntu.com/web-style-guide/scaffolding#footer
...
...
tpl/page.tpl.php
View file @
56832962
...
...
@@ -98,9 +98,10 @@
</header>
<header
class=
"banner global inverted"
role=
"banner"
>
<nav
class=
"nav-primary nav-left"
role=
"navigation"
>
<ul>
<li><a
href=
"#"
>
Somewhere
</a></li>
</ul>
<?php
print
theme
(
'links__system_main_menu'
,
array
(
'links'
=>
$valencia_menu
,
'id'
=>
'subheader'
));
?>
<form
action=
"/search"
id=
"search-form"
class=
"header-search"
>
<input
type=
"search"
maxlength=
"255"
name=
"q"
id=
"edit-keys"
class=
"form-text"
placeholder=
"Cerca…"
value=
""
/>
<button
type=
"submit"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment