acf_field_checkbox::render_fieldpublicACF 3.6

Create the HTML interface for your field

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

Хуков нет.

Возвращает

n/a.

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

$acf_field_checkbox = new acf_field_checkbox();
$acf_field_checkbox->render_field( $field );
$field(обязательный)
.

Список изменений

С версии 3.6 Введена.

Код acf_field_checkbox::render_field() ACF 6.8.8

function render_field( $field ) {

	// reset vars
	$this->_values      = array();
	$this->_all_checked = true;

	// ensure array
	$field['value']   = acf_get_array( $field['value'] );
	$field['choices'] = acf_get_array( $field['choices'] );

	// hiden input
	acf_hidden_input( array( 'name' => $field['name'] ) );

	// vars
	$li = '';
	$ul = array(
		'class' => 'acf-checkbox-list',
		'role'  => 'group',
	);

	// Add aria-labelledby if field has an ID for proper screen reader announcement
	if ( ! empty( $field['id'] ) ) {
		$ul['aria-labelledby'] = $field['id'] . '-label';
	}

	// append to class
	$ul['class'] .= ' ' . ( $field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl' );
	$ul['class'] .= ' ' . $field['class'];

	// checkbox saves an array
	$field['name'] .= '[]';

	// choices
	if ( ! empty( $field['choices'] ) ) {

		// choices
		$li .= $this->render_field_choices( $field );

		// toggle
		if ( $field['toggle'] ) {
			$li = $this->render_field_toggle( $field ) . $li;
		}
	}

	// custom
	if ( $field['allow_custom'] ) {
		$li .= $this->render_field_custom( $field );
	}

	// return
	echo '<ul ' . acf_esc_attrs( $ul ) . '>' . "\n" . $li . '</ul>' . "\n"; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped by specific render methods above.
}