1 installer.pages.inc | installer_browser_page($type) |
Page to display the projects.
Parameters
$type: Type of project to view. Must be one of 'module', 'theme' or 'layout'.
Return value
Themed list of the projects.:
File
- core/
modules/ installer/ installer.pages.inc, line 16 - Page callbacks used by the Installer browse pages.
Code
function installer_browser_page($type) {
backdrop_add_js(backdrop_get_path('module', 'installer') . '/js/installer.project_list.js');
module_load_include('inc', 'installer', 'installer.browser');
// Show a warning if no zip extension available, but allow to browse and
// select to view available releases. Install blocked on select versions page.
installer_browser_check_zip_loaded();
// Show link to enable page if recently installed modules were not yet
// enabled.
$recent_projects = installer_browser_get_installed_projects();
foreach ($recent_projects as $project) {
if ($project['type'] === 'module') {
backdrop_set_message(t('You have recently installed modules. <a href="@url">Continue to the enable page.</a>', array('@url' => url('admin/installer/install/enable'))), 'status', FALSE);
}
}
switch ($type) {
case 'layout':
backdrop_set_title(t('Install layout templates'));
break;
case 'module':
backdrop_set_title(t('Install modules'));
break;
case 'theme':
backdrop_set_title(t('Install themes'));
break;
default:
break;
}
// Save needed filters to session.
if (isset($_GET['repository'])) {
$_SESSION['installer_browser_sever_filter'] = $_GET['repository'];
}
if (isset($_GET['order'])) {
$_SESSION['installer_browser_order_filter_' . $type] = $_GET['order'];
}
if (isset($_GET['sort'])) {
$_SESSION['installer_browser_sort_filter_' . $type] = $_GET['sort'];
}
// Build the filters.
$backdrop_version = explode('.', BACKDROP_CORE_COMPATIBILITY);
$filters = array(
'version' => $backdrop_version[0],
'type' => $type,
);
// Add filters.
if (isset($_SESSION['installer_browser_text_filter_' . $type])) {
$filters['text'] = $_SESSION['installer_browser_text_filter_' . $type];
}
if (isset($_SESSION['installer_browser_order_filter_' . $type])) {
$filters['order'] = $_SESSION['installer_browser_order_filter_' . $type];
}
if (isset($_SESSION['installer_browser_sort_filter_' . $type])) {
$filters['sort'] = $_SESSION['installer_browser_sort_filter_' . $type];
}
$filters['items_per_page'] = 20;
$filters['page'] = isset($_GET['page']) ? $_GET['page'] : 0;
// Get the projects to display here based on the filters.
$results = installer_browser_fetch_results($filters);
// Add defaults to prevent PHP errors if server is down.
$results += array(
'total' => 0,
'projects' => array(),
);
// Save the listed projects in the session so it can be used.
$_SESSION['installer_browser_listed_projects'] = $results['projects'];
$list = array();
foreach ($results['projects'] as $project) {
$list[] = $project;
}
// Add the pager.
$total = $results['total'];
$items_per_page = 20;
$page = pager_default_initialize($total, $items_per_page);
$offset = $items_per_page * $page;
$start = ($total) ? $offset + 1 : 0;
$finish = $offset + $items_per_page;
if ($finish > $total) {
$finish = $total;
}
$filter_form = backdrop_get_form('installer_browser_filters_form', $type);
$sort_options = installer_browser_get_sort_options();
$current_order = isset($_SESSION['installer_browser_order_filter_' . $type]) ? $_SESSION['installer_browser_order_filter_' . $type] : 'score';
$current_sort = isset($_SESSION['installer_browser_sort_filter_' . $type]) ? $_SESSION['installer_browser_sort_filter_' . $type] : 'desc';
$build = array();
$build['content'] = array(
'installer_browser_filter' => array(
'#markup' => backdrop_render($filter_form),
'#weight' => 0,
),
'installer_browser_sort_header' => array(
'#type' => 'item',
'#weight' => 2,
'#wrapper_attributes' => array('class' => array('installer-browser-sort')),
'#markup' => installer_browser_get_sort_widget($sort_options, $current_order, $current_sort),
),
'installer_browser_header' => array(
'#type' => 'item',
'#weight' => 5,
'#wrapper_attributes' => array('class' => array('installer-browser-page-number')),
'#markup' => t('Showing @start to @finish of @total.', array(
'@start' => $start, '@finish' => $finish, '@total' => $total)),
),
'installer_browser_list' => array(
'#markup' => theme('installer_browser_list', array('projects_list' => $list, 'type' => $type)),
'#weight' => 10,
),
'pager' => array(
'#theme' => 'pager',
'#weight' => 99,
),
);
return $build;
}