function views_blogspot_archive_with_link in Views Blogspot Archive 8
Theme the result set to HTML.
Parameters
array $results: Associate array in format Array([year(counter)] => Array([month(counter)] => Array([nid] => title)))
string $year_to_expand: Which year to be shown in archive. A full numeric representation of a year, 4 digit.
string $month_to_expand: Which month to be shown in archive. Numeric representation of a month, with leading zeros.
string $viewPage: Views archive settings.
Return value
array An HTML string.
1 call to views_blogspot_archive_with_link()
- template_preprocess_views_blogspot_archive_view_archive in templates/
views_blogspot_archive.theme.inc - Prepares variables for view templates.
File
- templates/
views_blogspot_archive.theme.inc, line 179 - Preprocessors and helper functions to make theming easier.
Code
function views_blogspot_archive_with_link(array $results, $year_to_expand, $month_to_expand, $viewPage) {
$items = array();
if (!empty($results)) {
foreach ($results as $year => $months) {
// $year_parts[0] contain year value and $year_parts[1] contains count.
$year_parts = explode(' ', $year);
// Check for active year branch and block.
$active_year = $year_to_expand == $year_parts[0] ? TRUE : FALSE;
$child_months = array();
if ($active_year) {
// Loop through active year's month.
foreach ($months as $month => $entities) {
// $month_parts[0] contain int month and current interface month. $month_parts[1] contains count.
$month_parts = explode(' ', $month);
$month_items = explode('::', $month_parts[0]);
// Check for active month and block.
$active_month = $year_to_expand == $year_parts[0] && $month_to_expand == $month_items[0] ? TRUE : FALSE;
$child_entities = array();
if ($active_month) {
$count = 1;
// Loop through active month's node.
foreach ($entities as $entity) {
// $archive_items number of nodes display in expanded archive.
$link_obj = Link::fromTextAndUrl(t($entity
->label()), $entity
->toUrl());
$link_element = $link_obj
->toRenderable();
$child_entities[] = render($link_element);
$count = $count != 0 ? $count + 1 : 0;
}
}
$link_obj = Link::fromTextAndUrl($month_items[1], Url::fromRoute($viewPage, array(), array(
'query' => array(
'year' => $year_parts[0],
'month' => $month_items[0],
),
)));
$link_element = $link_obj
->toRenderable();
$child_months[] = array(
'#markup' => render($link_element) . ' <span>' . $month_parts[1] . '</span>',
'children' => $child_entities,
);
}
}
$link_obj = Link::fromTextAndUrl(t($year_parts[0]), Url::fromRoute($viewPage, array(), array(
'query' => array(
'year' => $year_parts[0],
),
)));
$link_element = $link_obj
->toRenderable();
$items[] = array(
'#markup' => render($link_element) . ' <span>' . $year_parts[1] . '</span>',
'children' => $child_months,
);
}
}
else {
$items[] = t('No posts available.');
}
return $items;
}