/** * Listens to sympal.load_config_form to load the configuration form */ public function loadConfigForm(sfEvent $event) { $form = $event->getSubject(); if (sfSympalConfig::isI18nEnabled()) { $cultures = sfCultureInfo::getCultures(sfCultureInfo::NEUTRAL); $languages = array(); foreach ($cultures as $key => $value) { $formatted = format_language($value); if (!$formatted) { $formatted = format_language($value, 'en'); } if ($formatted) { $languages[$value] = $formatted; } } asort($languages); $widget = new sfWidgetFormChoice(array('multiple' => true, 'choices' => $languages)); $validator = new sfValidatorChoice(array('multiple' => true, 'choices' => array_keys($languages))); $form->addSetting(null, 'language_codes', 'Available Cultures', $widget, $validator); $languageForm = new sfFormLanguage(sfContext::getInstance()->getUser(), array('languages' => sfSympalConfig::getLanguageCodes())); $widgetSchema = $languageForm->getWidgetSchema(); $validatorSchema = $languageForm->getValidatorSchema(); $form->addSetting(null, 'default_culture', 'Default Culture', $widgetSchema['language'], $validatorSchema['language']); } $form->addSetting(null, 'default_rendering_module', 'Default Rendering Module'); $form->addSetting(null, 'default_rendering_action', 'Default Rendering Action'); $form->addSetting(null, 'breadcrumbs_separator', 'Breadcrumbs Separator'); $form->addSetting(null, 'elastic_textareas', 'Elastic Textareas', 'InputCheckbox', 'Boolean'); $form->addSetting(null, 'check_for_upgrades_on_dashboard', 'Check for Upgrades', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'enabled', 'Enabled?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'super', 'Enable Super Cache?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'with_layout', 'With layout?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'lifetime', 'Lifetime'); }
<?php $user = sfContext::getInstance()->getUser(); $form = new sfFormLanguage($user, array('languages' => sfSympalConfig::getLanguageCodes())); unset($form[$form->getCSRFFieldName()]); $widgetSchema = $form->getWidgetSchema(); $widgetSchema['language']->setAttribute('onChange', "this.form.submit();"); ?> <?php echo $form->renderFormTag(url_for('@sympal_change_language_form')); ?> <?php echo $form['language']; ?> </form>
public function loadConfigForm(sfEvent $event) { $form = $event->getSubject(); $form->addSetting(null, 'rows_per_page', 'Rows Per Page'); if (sfSympalConfig::isI18nEnabled()) { $cultures = sfCultureInfo::getCultures(sfCultureInfo::NEUTRAL); $languages = array(); foreach ($cultures as $key => $value) { $formatted = format_language($value); if (!$formatted) { $formatted = format_language($value, 'en'); } if ($formatted) { $languages[$value] = $formatted; } } asort($languages); $widget = new sfWidgetFormChoice(array('multiple' => true, 'choices' => $languages)); $validator = new sfValidatorChoice(array('multiple' => true, 'choices' => array_keys($languages))); $form->addSetting(null, 'language_codes', 'Available Cultures', $widget, $validator); $languageForm = new sfFormLanguage(sfContext::getInstance()->getUser(), array('languages' => sfSympalConfig::getLanguageCodes())); $widgetSchema = $languageForm->getWidgetSchema(); $validatorSchema = $languageForm->getValidatorSchema(); $form->addSetting(null, 'default_culture', 'Default Culture', $widgetSchema['language'], $validatorSchema['language']); } $array = sfSympalFormToolkit::getThemeWidgetAndValidator(); $form->addSetting(null, 'default_theme', 'Default Theme', $array['widget'], $array['validator']); $form->addSetting(null, 'default_rendering_module', 'Default Rendering Module'); $form->addSetting(null, 'default_rendering_action', 'Default Rendering Action'); $form->addSetting(null, 'recaptcha_public_key', 'Recaptcha Public Key'); $form->addSetting(null, 'recaptcha_private_key', 'Recaptcha Private Key'); $form->addSetting(null, 'breadcrumbs_separator', 'Breadcrumbs Separator'); $form->addSetting(null, 'default_from_email_address', 'Default From Address'); $form->addSetting(null, 'enable_markdown_editor', 'Enable Markdown Editor', 'InputCheckbox', 'Boolean'); $form->addSetting(null, 'elastic_textareas', 'Elastic Textareas', 'InputCheckbox', 'Boolean'); $form->addSetting(null, 'check_for_upgrades_on_dashboard', 'Check for Upgrades', 'InputCheckbox', 'Boolean'); $form->addSetting('plugin_api', 'username', 'Username or API Key'); $form->addSetting('plugin_api', 'password'); $form->addSetting('page_cache', 'enabled', 'Enabled?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'super', 'Enable Super Cache?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'with_layout', 'With layout?', 'InputCheckbox', 'Boolean'); $form->addSetting('page_cache', 'lifetime', 'Lifetime'); }
$sessionPath = sys_get_temp_dir() . '/sessions_' . rand(11111, 99999); $storage = new sfSessionTestStorage(array('session_path' => $sessionPath)); $user = new sfUser($dispatcher, $storage); $user->setCulture('en'); $request = new sfWebRequest($dispatcher); // __construct() $t->diag('__construct()'); try { new sfFormLanguage($user); $t->fail('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } catch (RuntimeException $e) { $t->pass('__construct() throws a RuntimeException if you don\'t pass a "languages" option'); } $form = new sfFormLanguage($user, array('languages' => array('en', 'fr'))); $t->is($form->getDefault('language'), 'en', '__construct() sets the default language value to the user language'); $w = $form->getWidgetSchema(); $t->is($w['language']->getOption('languages'), array('en', 'fr'), '__construct() uses the "languages" option for the select form widget'); $v = $form->getValidatorSchema(); $t->is($v['language']->getOption('languages'), array('en', 'fr'), '__construct() uses the "languages" option for the validator'); // ->process() $t->diag('->process()'); // with CSRF disabled $t->diag('with CSRF disabled'); sfForm::disableCSRFProtection(); $form = new sfFormLanguage($user, array('languages' => array('en', 'fr'))); $request->setParameter('language', 'fr'); $t->is($form->process($request), true, '->process() returns true if the form is valid'); $t->is($user->getCulture(), 'fr', '->process() changes the user culture'); $request->setParameter('language', 'es'); $t->is($form->process($request), false, '->process() returns true if the form is not valid'); $t->is($form['language']->getError()->getCode(), 'invalid', '->process() throws an error if the language is not in the languages option');