Code Duplication    Length = 19-20 lines in 2 locations

includes/htmlform/HTMLCheckMatrix.php 1 location

@@ 227-245 (lines=19) @@
224
	 *
225
	 * @return array
226
	 */
227
	function loadDataFromRequest( $request ) {
228
		if ( $this->mParent->getMethod() == 'post' ) {
229
			if ( $request->wasPosted() ) {
230
				// Checkboxes are not added to the request arrays if they're not checked,
231
				// so it's perfectly possible for there not to be an entry at all
232
				return $request->getArray( $this->mName, [] );
233
			} else {
234
				// That's ok, the user has not yet submitted the form, so show the defaults
235
				return $this->getDefault();
236
			}
237
		} else {
238
			// This is the impossible case: if we look at $_GET and see no data for our
239
			// field, is it because the user has not yet submitted the form, or that they
240
			// have submitted it with all the options unchecked. We will have to assume the
241
			// latter, which basically means that you can't specify 'positive' defaults
242
			// for GET forms.
243
			return $request->getArray( $this->mName, [] );
244
		}
245
	}
246
247
	function getDefault() {
248
		if ( isset( $this->mDefault ) ) {

includes/htmlform/HTMLMultiSelectField.php 1 location

@@ 107-126 (lines=20) @@
104
	 *
105
	 * @return string
106
	 */
107
	function loadDataFromRequest( $request ) {
108
		if ( $this->mParent->getMethod() == 'post' ) {
109
			if ( $request->wasPosted() ) {
110
				# Checkboxes are just not added to the request arrays if they're not checked,
111
				# so it's perfectly possible for there not to be an entry at all
112
				return $request->getArray( $this->mName, [] );
113
			} else {
114
				# That's ok, the user has not yet submitted the form, so show the defaults
115
				return $this->getDefault();
116
			}
117
		} else {
118
			# This is the impossible case: if we look at $_GET and see no data for our
119
			# field, is it because the user has not yet submitted the form, or that they
120
			# have submitted it with all the options unchecked? We will have to assume the
121
			# latter, which basically means that you can't specify 'positive' defaults
122
			# for GET forms.
123
			# @todo FIXME...
124
			return $request->getArray( $this->mName, [] );
125
		}
126
	}
127
128
	function getDefault() {
129
		if ( isset( $this->mDefault ) ) {