function facetapi_facet_dependencies_form in Facet API 6.3
Same name and namespace in other branches
- 7.2 facetapi.admin.inc \facetapi_facet_dependencies_form()
- 7 facetapi.admin.inc \facetapi_facet_dependencies_form()
Form constructor for the facet dependency settings form.
Parameters
FacetapiAdapter $adapter: The adapter object the settings apply to.
array $realm: The realm definition.
array $dependencies: An array of dependencies.
See also
facetapi_facet_dependencies_form_submit()
1 string reference to 'facetapi_facet_dependencies_form'
- facetapi_menu in ./
facetapi.module - Implements hook_menu().
File
- ./
facetapi.admin.inc, line 1061 - Admin page callbacks for the Facet API module.
Code
function facetapi_facet_dependencies_form(&$form_state, FacetapiAdapter $adapter, array $realm, array $dependencies) {
$form = array();
// We have to set the title due to contextual link magic.
// @see http://drupal.org/node/1147588#comment-4428940
$facet = facetapi_facet_load(arg(6), $adapter
->getSearcher());
drupal_set_title(t('Configure facet dependencies for @label', array(
'@label' => $facet['label'],
)));
// Adds Facet API settings, excluded values aren't saved.
$form['#facetapi'] = array(
'adapter' => $adapter,
'realm' => $realm,
'settings' => FALSE,
'defaults' => array(),
);
$form['description'] = array(
'#prefix' => '<div class="facetapi-realm-description">',
'#value' => t('Dependencies are conditions that must be met in order for the facet to be processed by the server and displayed to the user. Hiding facets via the core block system or through the Drupal forms API will not prevent the server from processing the facets.'),
'#suffix' => "</div>\n",
);
$form['plugins'] = array(
'#type' => 'vertical_tabs',
'#weight' => 10,
);
// Iterates over plugins, adds settings as vertical tabs.
$plugins = ctools_get_plugins('facetapi', 'dependencies');
foreach ($dependencies as $plugin) {
// Only gets settings once.
if (!$form['#facetapi']['settings']) {
$settings = $adapter
->getFacet($plugin
->getFacet())
->getSettings();
$form['#facetapi']['settings'] = $settings;
}
// Initializes vertical tab.
$id = $plugin
->getId();
$form[$id] = array(
'#type' => 'fieldset',
'#title' => check_plain($plugins[$id]['handler']['label']),
'#group' => 'plugins',
);
// Allows plugin to add settings to the form, adds defaults.
$plugin
->settingsForm($form, $form_state);
$form['#facetapi']['defaults'] += $plugin
->getDefaultSettings();
// Removes vertical tab if nothing was added.
if (!element_children($form[$id])) {
unset($form[$id]);
}
}
$form['actions'] = array(
'#weight' => 20,
);
// Gets destination from query string which is set when the page is navigated
// to via a contextual link. Builds messages based on where user came from.
if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
$submit_text = t('Save and go back to search page');
$cancel_title = t('Return to the search page without saving configuration changes.');
$url = facetapi_parse_url($_GET['destination']);
}
else {
$submit_text = t('Save configuration');
$cancel_title = t('Return to the realm settings page without saving configuration changes.');
$url = array();
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $submit_text,
);
// Do not show the button if the page was navigated to via a contextual link
// because it would redirect the user back to the search page.
$form['actions']['submit_realm'] = array(
'#type' => 'submit',
'#access' => !$url,
'#value' => t('Save and go back to realm settings'),
);
$options = array(
'attributes' => array(
'title' => $cancel_title,
),
);
if ($url) {
$options['query'] = $url['query'];
}
$form['actions']['cancel'] = array(
'#value' => l(t('Cancel'), !$url ? $adapter
->getPath($realm['name']) : $url['path'], $options),
);
$form['#submit'][] = 'facetapi_facet_dependencies_form_submit';
return $form;
}