acf_field_flexible_content::render_field()publicACF 3.6

Create the HTML interface for your field

{} Это метод класса: acf_field_flexible_content{}

Возвращает

null. Ничего.

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

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

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

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

Код acf_field_flexible_content::render_field() ACF 5.10.2

<?php
function render_field( $field ) {

	// defaults
	if ( empty( $field['button_label'] ) ) {

		$field['button_label'] = $this->defaults['button_label'];

	}

	// sort layouts into names
	$layouts = array();

	foreach ( $field['layouts'] as $k => $layout ) {

		$layouts[ $layout['name'] ] = $layout;

	}

	// vars
	$div = array(
		'class'    => 'acf-flexible-content',
		'data-min' => $field['min'],
		'data-max' => $field['max'],
	);

	// empty
	if ( empty( $field['value'] ) ) {
		$div['class'] .= ' -empty';
	}

	// no value message
	$no_value_message = __( 'Click the "%s" button below to start creating your layout', 'acf' );
	$no_value_message = apply_filters( 'acf/fields/flexible_content/no_value_message', $no_value_message, $field );
	$no_value_message = sprintf( $no_value_message, $field['button_label'] );

	?>
<div <?php acf_esc_attr_e( $div ); ?>>
	
	<?php acf_hidden_input( array( 'name' => $field['name'] ) ); ?>
	
	<div class="no-value-message">
	<?php echo acf_esc_html( $no_value_message ); ?>
	</div>
	
	<div class="clones">
	<?php foreach ( $layouts as $layout ) : ?>
		<?php $this->render_layout( $field, $layout, 'acfcloneindex', array() ); ?>
<?php endforeach; ?>
	</div>
	
	<div class="values">
	<?php
	if ( ! empty( $field['value'] ) ) :

		foreach ( $field['value'] as $i => $value ) :

			// validate
			if ( empty( $layouts[ $value['acf_fc_layout'] ] ) ) {
				continue;
			}

			// render
			$this->render_layout( $field, $layouts[ $value['acf_fc_layout'] ], $i, $value );

		endforeach;

	endif;
	?>
	</div>
	
	<div class="acf-actions">
<a class="acf-button button button-primary" href="#" data-name="add-layout"><?php echo acf_esc_html( $field['button_label'] ); ?></a>
	</div>
	
	<script type="text-html" class="tmpl-popup"><ul>
	<?php
	foreach ( $layouts as $layout ) :

			$atts = array(
				'href'        => '#',
				'data-layout' => $layout['name'],
				'data-min'    => $layout['min'],
				'data-max'    => $layout['max'],
			);

			?>
	<li><a <?php acf_esc_attr_e( $atts ); ?>><?php echo acf_esc_html( $layout['label'] ); ?></a></li>
		<?php

endforeach;
	?>
</ul>
	</script>
	
</div>
	<?php

}