[ticket/11201] Move grabbing the input of the language options to type class

PHPBB3-11201
This commit is contained in:
Joas Schilling 2014-01-16 16:00:52 +01:00
parent 78603bb96d
commit 0bdec35cd4
8 changed files with 99 additions and 27 deletions

View file

@ -840,7 +840,7 @@ class acp_profile
// Build options based on profile type
$profile_field = $phpbb_container->get('profilefields.type.' . $cp->profile_types[$field_type]);
$options = $profile_field->get_options($this->lang_defs, $cp->vars);
$options = $profile_field->get_options($this->lang_defs['iso'][$config['default_lang']], $cp->vars);
foreach ($options as $num => $option_ary)
{
@ -1101,13 +1101,14 @@ class acp_profile
$db->sql_query($sql);
}
$type_collection = $phpbb_container->get('profilefields.type_collection');
$profile_type = $type_collection['profilefields.type.' . $cp->profile_types[$field_type]];
if ($action == 'create')
{
$field_ident = 'pf_' . $field_ident;
$db_tools = $phpbb_container->get('dbal.tools');
$type_collection = $phpbb_container->get('profilefields.type_collection');
$profile_type = $type_collection['profilefields.type.' . $cp->profile_types[$field_type]];
list($sql_type, $null) = $db_tools->get_column_type($profile_type->get_database_column_type());
$profile_sql[] = $this->add_field_ident($field_ident, $sql_type);
@ -1164,23 +1165,7 @@ class acp_profile
}
}
// These are always arrays because the key is the language id...
$cp->vars['l_lang_name'] = utf8_normalize_nfc(request_var('l_lang_name', array(0 => ''), true));
$cp->vars['l_lang_explain'] = utf8_normalize_nfc(request_var('l_lang_explain', array(0 => ''), true));
$cp->vars['l_lang_default_value'] = utf8_normalize_nfc(request_var('l_lang_default_value', array(0 => ''), true));
if ($field_type != FIELD_BOOL)
{
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => ''), true));
}
else
{
/**
* @todo check if this line is correct...
$cp->vars['l_lang_default_value'] = request_var('l_lang_default_value', array(0 => array('')), true);
*/
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => array('')), true));
}
$cp->vars = $profile_type->get_language_options_input($cp->vars);
if ($cp->vars['lang_options'])
{

View file

@ -48,6 +48,14 @@ class lang_helper
foreach ($lang_options as $num => $var)
{
if (!isset($this->options_lang[$field_id]))
{
$this->options_lang[$field_id] = array();
}
if (!isset($this->options_lang[$field_id][$lang_id]))
{
$this->options_lang[$field_id][$lang_id] = array();
}
$this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
}
}
@ -104,7 +112,7 @@ class lang_helper
*/
public function get($field_id, $lang_id, $field_value = null)
{
if (!is_null($field_value))
if (is_null($field_value))
{
return $this->options_lang[$field_id][$lang_id];
}

View file

@ -144,7 +144,7 @@ class type_bool implements type_interface
{
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value'];
$default_value = $profile_row['field_default_value'];
// checkbox - set the value to "true" if it has been set to 1
if ($profile_row['field_length'] == 2)
@ -211,4 +211,22 @@ class type_bool implements type_interface
return $options;
}
/**
* {@inheritDoc}
*/
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
/**
* @todo check if this line is correct...
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => array('')), true);
*/
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => array('')), true);
return $field_data;
}
}

View file

@ -177,6 +177,7 @@ class type_date implements type_interface
public function generate_field($profile_row, $preview_options = false)
{
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident'];
$now = getdate();
@ -186,14 +187,14 @@ class type_date implements type_interface
{
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
}
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]));
}
else
{
if ($preview_options !== false && $profile_row['field_default_value'] == 'now')
{
$profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident]));
list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]));
}
else
{
@ -257,4 +258,17 @@ class type_date implements type_interface
return $options;
}
/**
* {@inheritDoc}
*/
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true);
return $field_data;
}
}

View file

@ -153,7 +153,7 @@ class type_dropdown implements type_interface
{
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value'];
$default_value = $profile_row['field_default_value'];
$value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
@ -209,4 +209,17 @@ class type_dropdown implements type_interface
return $options;
}
/**
* {@inheritDoc}
*/
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true);
return $field_data;
}
}

View file

@ -124,7 +124,7 @@ class type_int implements type_interface
{
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value'];
$default_value = $profile_row['field_default_value'];
if ($this->request->is_set($field_ident))
{
@ -183,4 +183,17 @@ class type_int implements type_interface
return $options;
}
/**
* {@inheritDoc}
*/
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true);
return $field_data;
}
}

View file

@ -102,7 +102,15 @@ interface type_interface
* Get the options we need to display for the language input fields in the ACP
*
* @param array $field_data Array with data for this field
* @return array Returns the language options we need to generate
* @return array Returns the language options we need to generate
*/
public function get_language_options($field_data);
/**
* Get the input for the supplied language options
*
* @param array $field_data Array with data for this field
* @return array Returns the language options we need to generate
*/
public function get_language_options_input($field_data);
}

View file

@ -109,4 +109,17 @@ abstract class type_string_common
{
return 'pf_' . $field_data['field_ident'];
}
/**
* {@inheritDoc}
*/
public function get_language_options_input($field_data)
{
$field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true);
$field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true);
$field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true);
$field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true);
return $field_data;
}
}