Created
September 23, 2011 10:01
-
-
Save woeldiche/1237067 to your computer and use it in GitHub Desktop.
Move fields til other regions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_page_alter(). | |
* Moves field_title_image from node to 'featured' region. | |
* Moves secondary content from node (downloads, links) to 'sidebar-two' region. | |
*/ | |
function pufdk_page_alter(&$page) { | |
// Declare variables | |
$image = array(); | |
$secondary_content = array(); | |
// Check if we are on a node page | |
if ($node = menu_get_object()) { | |
// ---- / Move title image to featured / ----- | |
if (isset($page['content']['system_main']['nodes'][$node->nid]['field_title_image'])) { | |
// Save image to a variable | |
$image = $page['content']['system_main']['nodes'][$node->nid]['field_title_image']; | |
// Remove image from the system_main block | |
unset($page['content']['system_main']['nodes'][$node->nid]['field_title_image']); | |
// Insert the image into another region instead | |
$image['#weight'] = 0; | |
$page['featured']['field_title_image'] = $image; | |
// Check if standard properties of the region exists and add them as necessary | |
if (!isset($page['featured']['#region']) && !isset($page['featured']['#theme_wrapper'])) { | |
$page['featured']['#region'] = 'featured'; | |
$page['featured']['#theme_wrappers'] = array('region'); | |
} | |
} | |
// ---- / Move secondary node fields to sidebar two / ---- | |
// Check if node contains links og downloads | |
$exists_downloads = isset($page['content']['system_main']['nodes'][$node->nid]['field_download']); | |
$exists_links = isset($page['content']['system_main']['nodes'][$node->nid]['field_links']); | |
if ($exists_downloads || $exists_links) { | |
// Move downloads | |
if ($exists_downloads) { | |
// Copy downloads to sidebar and unset original | |
$downloads = $page['content']['system_main']['nodes'][$node->nid]['field_download']; | |
// Insert the downloads into top of sidebar region instead | |
$downloads['#weight'] = -2; | |
$page['sidebar_two']['field_downloads'] = $downloads; | |
// Make sure original isn't displayed | |
$page['content']['system_main']['nodes'][$node->nid]['field_download']['#access'] = FALSE; | |
} | |
// Move links | |
if ($exists_links) { | |
// Copy links to sidebar and unset original | |
$links = $page['content']['system_main']['nodes'][$node->nid]['field_links']; | |
// Insert the links into top of sidebar region instead | |
$links['#weight'] = -1; | |
$page['sidebar_two']['field_links'] = $links; | |
// Make sure original isn't displayed | |
$page['content']['system_main']['nodes'][$node->nid]['field_links']['#access'] = FALSE; | |
} | |
// Resort sidebar_two | |
$page['sidebar_two']['#sorted'] = FALSE; | |
// Add basic region properties if needed | |
if (!isset($page['sidebar_two']['#region']) && !isset($page['sidebar_two']['#theme_wrapper'])) { | |
$page['sidebar_two']['#region'] = 'sidebar_two'; | |
$page['sidebar_two']['#theme_wrappers'] = array('region'); | |
} | |
} // endif $exists_downloads || $exits_links | |
} // endif check for node page | |
} | |
/** | |
* Implements hook_page_alter(). | |
* Adds ' È ' to the end of the breadcrumb. | |
*/ | |
function pufdk_breadcrumb($variables) { | |
$breadcrumb = $variables['breadcrumb']; | |
if (!empty($breadcrumb)) { | |
// Provide a navigational heading to give context for breadcrumb links to | |
// screen-reader users. Make the heading invisible with .element-invisible. | |
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>'; | |
$output .= '<em class="breadcrumb">' . implode(' È ', $breadcrumb) . '</em>'; | |
return $output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment