Completed
Push — master ( ac7d8e...ec16eb )
by Stephanie
05:53 queued 02:59
created

FrmFieldTextarea   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A field_settings_for_type() 0 6 1
A extra_field_opts() 0 5 1
A show_on_form_builder() 0 13 3
A prepare_display_value() 0 5 1
A front_field_input() 0 10 2
1
<?php
2
3
/**
4
 * @since 3.0
5
 */
6
class FrmFieldTextarea extends FrmFieldType {
7
8
	/**
9
	 * @var string
10
	 * @since 3.0
11
	 */
12
	protected $type = 'textarea';
13
14
	protected $is_tall = true;
15
16
	protected function field_settings_for_type() {
17
		return array(
18
			'size'           => true,
19
			'clear_on_focus' => true,
20
		);
21
	}
22
23
	protected function extra_field_opts() {
24
		return array(
25
			'max' => '5',
26
		);
27
	}
28
29
	/**
30
	 * @param string $name
31
	 */
32
	public function show_on_form_builder( $name = '' ) {
33
		$size = FrmField::get_option( $this->field, 'size' );
34
		$size_html = $size ? ' style="width:' . esc_attr( $size . ( is_numeric( $size ) ? 'px' : '' ) ) . '";' : '';
35
36
		$max = FrmField::get_option( $this->field, 'max' );
37
		$default_value = FrmAppHelper::esc_textarea( force_balance_tags( $this->get_field_column('default_value') ) );
38
39
		echo '<textarea name="' . esc_attr( $this->html_name( $name ) ) . '" ' .
40
			$size_html . ' rows="' . esc_attr( $max ) . '" ' .
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$size_html'
Loading history...
41
			'id="' . esc_attr( $this->html_id() ) . '" class="dyn_default_value">' .
42
			$default_value .
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_value'
Loading history...
43
			'</textarea>';
44
	}
45
46
	protected function prepare_display_value( $value, $atts ) {
47
		FrmFieldsHelper::run_wpautop( $atts, $value );
48
49
		return $value;
50
	}
51
52
	/**
53
	 * @param array $args
54
	 * @param array $shortcode_atts
55
	 *
56
	 * @return string
57
	 */
58
	public function front_field_input( $args, $shortcode_atts ) {
59
		$input_html = $this->get_field_input_html_hook( $this->field );
60
		$this->add_aria_description( $args, $input_html );
61
		$rows = ( $this->field['max'] ) ? 'rows="' . esc_attr( $this->field['max'] ) . '" ' : '';
62
63
		return '<textarea name="' . esc_attr( $args['field_name'] ) . '" id="' . esc_attr( $args['html_id'] ) . '" ' .
64
			$rows . $input_html . '>' .
65
			FrmAppHelper::esc_textarea( $this->field['value'] ) .
66
			'</textarea>';
67
	}
68
}
69