| 1 system.module | system_icon_browser_form($form, &$form_state) |
Display the page of icons with filters.
File
- core/
modules/ system/ system.module, line 4954 - Configuration system that lets administrators modify the workings of the site.
Code
function system_icon_browser_form($form, &$form_state) {
if (isset($form_state['input']['dialogOptions']['target'])) {
$form_state['storage']['dialog_selector'] = $form_state['input']['dialogOptions']['target'];
}
$config = config('system.core');
backdrop_add_css(backdrop_get_path('module', 'system') . '/css/icon-browser.css');
$icons = icon_get_all_details();
$params = array(
'project_type' => 'any',
'style' => 'any',
'keyword' => '',
);
// Set filter variables from the $_GET variable if set.
foreach ($params as $param => $default_value) {
if (!empty($_GET[$param])) {
${$param}= $_GET[$param];
}
else {
${$param}= $default_value;
}
}
$results = array();
$available_project_types = array();
$available_styles = array();
foreach ($icons as $icon) {
$available_project_types[$icon['project_type']] = $icon['project_type'];
$available_styles[$icon['style']] = $icon['style'];
if ($project_type != 'any' && $icon['project_type'] != $project_type) {
continue;
}
if ($style != 'any' && ($icon['style'] != $style)) {
continue;
}
$search_text = implode(' ', $icon);
if ($keyword && stripos($search_text, $keyword) === FALSE) {
continue;
}
$results[] = $icon;
}
$project_type_options = array_intersect_key(array(
'core' => t('Core'),
'module' => t('Module'),
'theme' => t('Theme'),
), $available_project_types);
$icon_allowed_styles = icon_allowed_styles();
$style_options = array_intersect_key($icon_allowed_styles, $available_styles);
$form = array(
'#icons' => $results,
'#prefix' => '<div id="system-icon-browser-form-wrapper">',
'#suffix' => '</div>',
);
$form['icon_filters'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('icon-browser-filters-wrapper'),
),
);
if (count($available_project_types) > 1) {
$form['icon_filters']['project_type'] = array(
'#type' => 'select',
'#title' => t('Project type'),
'#options' => array(
'any' => t('Any'),
) + $project_type_options,
'#default_value' => $project_type,
);
}
$form['icon_filters']['style'] = array(
'#type' => 'select',
'#title' => t('Style'),
'#options' => array(
'any' => t('Any'),
) + $style_options,
'#default_value' => $style,
);
$form['icon_filters']['keyword'] = array(
'#type' => 'textfield',
'#title' => t('Keyword'),
'#default_value' => $keyword,
'#size' => 10,
);
$form['icon_filters']['submit'] = array(
'#type' => 'submit',
'#submit' => array('system_icon_browser_form_submit'),
'#value' => t('Filter'),
);
$form['icon_filters']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
);
$icons_per_page = $config->get('icon_browser_icons_per_page');
$filter_results = array();
if ($results) {
$current_page = pager_default_initialize(count($results), $icons_per_page);
$chunks = array_chunk($results, $icons_per_page, TRUE);
$filter_results = $chunks[$current_page];
}
$form['icons'] = array(
'#type' => 'container',
'#theme' => 'system_icon_browser_form_icons',
'#icons' => $results ? $filter_results : array(),
);
$form['pager'] = array(
'#prefix' => '<div id="system-icon-browser-pager">',
'#suffix' => '</div>',
'#markup' => theme('pager', array(
'quantity',
count($results),
'attributes' => array('class' => array('icon-browser-pager-link'))
)),
);
return $form;
}