[ticket/11201] Move field type depending preparation of the options to class

PHPBB3-11201
This commit is contained in:
Joas Schilling 2014-01-17 09:55:52 +01:00
parent 0bdec35cd4
commit 9653764fb1
7 changed files with 63 additions and 27 deletions

View file

@ -341,6 +341,7 @@ class acp_profile
$this->edit_lang_id = $field_row['lang_id'];
}
$field_type = $field_row['field_type'];
$profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]);
// Get language entries
$sql = 'SELECT *
@ -397,23 +398,6 @@ class acp_profile
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
);
// Text-based fields require the lang_default_value to be excluded
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
{
$exclude[1][] = 'lang_default_value';
}
// option-specific fields require lang_options to be excluded
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
{
$exclude[1][] = 'lang_options';
}
$cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']);
$cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
$cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
$cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
// Visibility Options...
$visibility_ary = array(
'field_required',
@ -425,6 +409,13 @@ class acp_profile
'field_hide',
);
$options = $profile_field->prepare_options_form($exclude, $visibility_ary);
$cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']);
$cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
$cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
$cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
foreach ($visibility_ary as $val)
{
$cp->vars[$val] = ($submit || $save) ? request_var($val, 0) : $field_row[$val];
@ -432,16 +423,6 @@ class acp_profile
$cp->vars['field_no_view'] = request_var('field_no_view', (int) $field_row['field_no_view']);
// A boolean field expects an array as the lang options
if ($field_type == FIELD_BOOL)
{
$options = utf8_normalize_nfc(request_var('lang_options', array(''), true));
}
else
{
$options = utf8_normalize_nfc(request_var('lang_options', '', true));
}
// If the user has submitted a form with options (i.e. dropdown field)
if ($options)
{

View file

@ -229,4 +229,14 @@ class type_bool implements type_interface
return $field_data;
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
$exclude_options[1][] = 'lang_options';
return $this->request->variable('lang_options', array(''), true);
}
}

View file

@ -271,4 +271,12 @@ class type_date implements type_interface
return $field_data;
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
return $this->request->variable('lang_options', '', true);
}
}

View file

@ -222,4 +222,14 @@ class type_dropdown implements type_interface
return $field_data;
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
$exclude_options[1][] = 'lang_options';
return $this->request->variable('lang_options', '', true);
}
}

View file

@ -196,4 +196,12 @@ class type_int implements type_interface
return $field_data;
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
return $this->request->variable('lang_options', '', true);
}
}

View file

@ -113,4 +113,13 @@ interface type_interface
* @return array Returns the language options we need to generate
*/
public function get_language_options_input($field_data);
/**
* Allows exclusion of options in single steps of the creation process
*
* @param array $exclude_options Array with options that should be excluded in the steps
* @param array $visibility_options Array with options responsible for the fields visibility
* @return mixed Returns the provided language options
*/
public function prepare_options_form(&$exclude_options, &$visibility_options);
}

View file

@ -122,4 +122,14 @@ abstract class type_string_common
return $field_data;
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
$exclude_options[1][] = 'lang_default_value';
return $this->request->variable('lang_options', '', true);
}
}