WPCF7_TagGeneratorGenerator::field_typeprivateCF7 1.0

Template method for field type field.

Метод класса: WPCF7_TagGeneratorGenerator{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->field_type( $options );
$options
.
По умолчанию: ''

Код WPCF7_TagGeneratorGenerator::field_type() CF7 6.1.5

private function field_type( $options = '' ) {
	$options = wp_parse_args( $options, array(
		'with_required' => false,
		'with_optional' => false,
		'select_options' => array(),
	) );

	$formatter = new WPCF7_HTMLFormatter();

	$formatter->append_start_tag( 'fieldset' );

	$formatter->append_start_tag( 'legend', array(
		'id' => $this->ref( 'type-legend' ),
	) );

	$formatter->append_preformatted(
		esc_html( __( 'Field type', 'contact-form-7' ) )
	);

	$formatter->end_tag( 'legend' );

	$formatter->append_start_tag( 'select', array(
		'data-tag-part' => 'basetype',
		'aria-labelledby' => $this->ref( 'type-legend' ),
	) );

	foreach ( (array) $options['select_options'] as $basetype => $title ) {
		$formatter->append_start_tag( 'option', array(
			'value' => $basetype,
		) );

		$formatter->append_preformatted( esc_html( $title ) );
	}

	$formatter->end_tag( 'select' );

	if ( $options['with_required'] ) {
		$formatter->append_start_tag( 'br' );
		$formatter->append_start_tag( 'label' );

		$formatter->append_start_tag( 'input', array(
			'type' => 'checkbox',
			'data-tag-part' => 'type-suffix',
			'value' => '*',
		) );

		$formatter->append_whitespace();

		$formatter->append_preformatted(
			esc_html( __( 'This is a required field.', 'contact-form-7' ) )
		);
	}

	if ( $options['with_optional'] ) {
		$formatter->append_start_tag( 'br' );
		$formatter->append_start_tag( 'label' );

		$formatter->append_start_tag( 'input', array(
			'type' => 'checkbox',
			'data-tag-part' => 'option',
			'data-tag-option' => 'optional',
			'checked' => true,
		) );

		$formatter->append_whitespace();

		$formatter->append_preformatted(
			esc_html( __( 'This checkbox is optional.', 'contact-form-7' ) )
		);
	}

	$formatter->print();
}