Code Duplication    Length = 41-41 lines in 2 locations

core/Field/Complex_Field.php 1 location

@@ 387-427 (lines=41) @@
384
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
385
	 * @return array
386
	 */
387
	public function to_json( $load ) {
388
		$complex_data = parent::to_json( $load );
389
390
		$groups_data = array();
391
		$values_data = array();
392
393
		foreach ( $this->groups as $group ) {
394
			$groups_data[] = $group->to_json( false );
395
		}
396
397
		foreach ( $this->values as $fields ) {
398
			$group = $this->get_group_by_name( $fields['type'] );
399
			unset( $fields['type'] );
400
401
			$data = array(
402
				'name' => $group->get_name(),
403
				'label' => $group->get_label(),
404
				'group_id' => $group->get_group_id(),
405
				'fields' => array(),
406
			);
407
408
			foreach ( $fields as $index => $field ) {
409
				$data['fields'][] = $field->to_json( false );
410
			}
411
412
			$values_data[] = $data;
413
		}
414
415
		$complex_data = array_merge( $complex_data, array(
416
			'layout' => $this->layout,
417
			'labels' => $this->labels,
418
			'min' => $this->get_min(),
419
			'max' => $this->get_max(),
420
			'multiple_groups' => count( $groups_data ) > 1,
421
			'groups' => $groups_data,
422
			'value' => $values_data,
423
			'collapsed' => $this->collapsed,
424
		) );
425
426
		return $complex_data;
427
	}
428
429
	/**
430
	 * The main Underscore template.

core/Field/Rich_Text_Field.php 1 location

@@ 396-436 (lines=41) @@
393
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
394
	 * @return array
395
	 */
396
	public function to_json( $load ) {
397
		$complex_data = parent::to_json( $load );
398
399
		$groups_data = array();
400
		$values_data = array();
401
402
		foreach ( $this->groups as $group ) {
403
			$groups_data[] = $group->to_json( false );
404
		}
405
406
		foreach ( $this->values as $fields ) {
407
			$group = $this->get_group_by_name( $fields['type'] );
408
			unset( $fields['type'] );
409
410
			$data = array(
411
				'name' => $group->get_name(),
412
				'label' => $group->get_label(),
413
				'group_id' => $group->get_group_id(),
414
				'fields' => array(),
415
			);
416
417
			foreach ( $fields as $index => $field ) {
418
				$data['fields'][] = $field->to_json( false );
419
			}
420
421
			$values_data[] = $data;
422
		}
423
424
		$complex_data = array_merge( $complex_data, array(
425
			'layout' => $this->layout,
426
			'labels' => $this->labels,
427
			'min' => $this->get_min(),
428
			'max' => $this->get_max(),
429
			'multiple_groups' => count( $groups_data ) > 1,
430
			'groups' => $groups_data,
431
			'value' => $values_data,
432
			'collapsed' => $this->collapsed,
433
		) );
434
435
		return $complex_data;
436
	}
437
438
	/**
439
	 * The main Underscore template.