ContentTranslationRedirectFormTrait.php in Content Translation Redirect 8
File
src/Form/ContentTranslationRedirectFormTrait.php
View source
<?php
namespace Drupal\content_translation_redirect\Form;
trait ContentTranslationRedirectFormTrait {
protected function redirectSettingsForm(array $settings, $default = FALSE) {
if ($default) {
$status_code_options = $this
->getStatusCodeOptions();
$message_description = $this
->t('Leave blank to not display the message. You can use <i>%language</i> to display the name of the language.');
}
else {
$status_code_options = [
'' => $this
->t('- Use default -'),
] + $this
->getStatusCodeOptions();
$message_description = $this
->t('Leave blank to use the default value. You can use <i>%language</i> to display the name of the language.');
}
$form['code'] = [
'#type' => 'select',
'#title' => $this
->t('Redirect status'),
'#options' => $status_code_options,
'#default_value' => isset($settings['code']) ? $settings['code'] : '',
];
$form['message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message after redirection'),
'#description' => $message_description,
'#default_value' => isset($settings['message']) ? $settings['message'] : '',
];
return $form;
}
protected function getStatusCodeOptions() {
return [
300 => $this
->t('300 Multiple Choices'),
301 => $this
->t('301 Moved Permanently'),
302 => $this
->t('302 Found'),
303 => $this
->t('303 See Other'),
304 => $this
->t('304 Not Modified'),
305 => $this
->t('305 Use Proxy'),
307 => $this
->t('307 Temporary Redirect'),
];
}
}