function _shorten_service_form in Shorten URLs 8
Same name and namespace in other branches
- 8.2 shorten.module \_shorten_service_form()
- 6 shorten.module \_shorten_service_form()
- 7.2 shorten.module \_shorten_service_form()
- 7 shorten.module \_shorten_service_form()
Form which displays a list of URL shortening services.
Parameters
$last_service: The last service used on this page, if applicable.
1 call to _shorten_service_form()
- ShortenShortenForm::buildForm in src/
Form/ ShortenShortenForm.php - Form constructor.
File
- ./
shorten.module, line 413 - Shortens URLs via external services.
Code
function _shorten_service_form($last_service = NULL) {
if (\Drupal::config('shorten.settings')
->get('shorten_show_service') && _shorten_method_default() != 'none') {
$all_services = \Drupal::moduleHandler()
->invokeAll('shorten_service');
$services = array();
$disallowed = unserialize(\Drupal::config('shorten.settings')
->get('shorten_invisible_services'));
foreach ($all_services as $key => $value) {
if (!$disallowed[$key]) {
$services[$key] = $key;
}
}
$default = \Drupal::config('shorten.settings')
->get('shorten_service');
if ($default == 'none') {
$default = 'TinyURL';
}
// Remember the last service that was used.
if (isset($_SESSION['shorten_service']) && $_SESSION['shorten_service']) {
$default = $_SESSION['shorten_service'];
}
// Anonymous users don't have $_SESSION, so we use the last service used on this page, if applicable.
if (!empty($last_service)) {
$default = $last_service;
}
$count = count($services);
if ($count > 1) {
if (isset($services[$default])) {
unset($default);
$default = NULL;
}
return array(
'#type' => 'select',
'#title' => t('Service'),
'#description' => t('The service to use to shorten the URL.'),
'#required' => TRUE,
'#default_value' => $default,
'#options' => $services,
);
}
elseif ($count) {
return array(
'#type' => 'value',
'#value' => array_pop($services),
);
}
return array(
'#type' => 'value',
'#value' => $default,
);
}
}