diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 14:41:01 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-17 21:13:46 +0100 |
commit | af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb (patch) | |
tree | 8ed2dbfbef3ebf5f08cce7443927a597c8140140 /phpBB/phpbb | |
parent | 67f477fc8f184e5b2585bda914e2fbbabf4afcd8 (diff) | |
download | forums-af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb.tar forums-af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb.tar.gz forums-af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb.tar.bz2 forums-af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb.tar.xz forums-af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb.zip |
[ticket/11201] Move preparation of hidden fields to type class
PHPBB3-11201
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_base.php | 20 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 30 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 25 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 11 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 15 |
5 files changed, 101 insertions, 0 deletions
diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index cd03af57f7..cb262d54a8 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -75,4 +75,24 @@ abstract class type_base implements type_interface return $current_value; } + + /** + * {@inheritDoc} + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data) + { + if (!$this->request->is_set($key)) + { + // Do not set this variable, we will use the default value + return null; + } + else if ($key == 'field_ident' && isset($field_data[$key])) + { + return $field_data[$key]; + } + else + { + return $this->request->variable($key, '', true); + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index acf20e93e0..f303e40213 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -296,4 +296,34 @@ class type_bool extends type_base return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } + + /** + * {@inheritDoc} + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data) + { + if ($key == 'l_lang_options' && $this->request->is_set('l_lang_options')) + { + return $this->request->variable($key, array(array('')), true); + } + else if ($key == 'field_default_value') + { + return $this->request->variable($key, $field_data[$key]); + } + else + { + if (!$this->request->is_set($key)) + { + return false; + } + else if ($key == 'field_ident' && isset($field_data[$key])) + { + return $field_data[$key]; + } + else + { + return ($key == 'lang_options') ? $this->request->variable($key, array(''), true) : $this->request->variable($key, '', true); + } + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 099d1dbb50..9c706af7a3 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -300,4 +300,29 @@ class type_date extends type_base return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } + + /** + * {@inheritDoc} + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data) + { + if ($key == 'field_default_value') + { + $always_now = $this->request->variable('always_now', 0); + + if ($always_now) + { + return 'now'; + } + else if ($this->request->is_set'field_default_value_day')) + { + $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); + $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); + $field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0); + return sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']); + } + } + + return parent::prepare_hidden_fields($step, $key, $action, $field_data); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 7cbdd30ddf..9ce975f676 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -143,4 +143,15 @@ interface type_interface * @return mixed Final value of the option */ public function get_excluded_options($key, $action, $current_value, &$field_data, $step); + + /** + * Allows manipulating the intended variables if needed + * + * @param string $key Name of the option + * @param int $step Step on which the option is hidden + * @param string $action Currently performed action (create|edit) + * @param array $field_data Array with data for this field + * @return mixed Final value of the option + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 4437334d2b..60abb2e421 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -140,4 +140,19 @@ class type_text extends type_string_common return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } + + /** + * {@inheritDoc} + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data) + { + if ($key == 'field_length' && $this->request->is_set('rows')) + { + $field_data['rows'] = $this->request->variable('rows', 0); + $field_data['columns'] = $this->request->variable('columns', 0); + return $field_data['rows'] . '|' . $field_data['columns']; + } + + return parent::prepare_hidden_fields($step, $key, $action, $field_data); + } } |