acf_field_flexible_content::render_layout()publicACF 5.0.0

render_layout

description

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

Хуков нет.

Возвращает

$post_id. (int)

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

$acf_field_flexible_content = new acf_field_flexible_content();
$acf_field_flexible_content->render_layout( $field, $layout, $i, $value );
$field (обязательный)
-
$layout (обязательный)
-
$i (обязательный)
-
$value (обязательный)
-

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

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

Код acf_field_flexible_content::render_layout() ACF 6.0.4

<?php
function render_layout( $field, $layout, $i, $value ) {

	// vars
	$order      = 0;
	$el         = 'div';
	$sub_fields = $layout['sub_fields'];
	$id         = ( $i === 'acfcloneindex' ) ? 'acfcloneindex' : "row-$i";
	$prefix     = $field['name'] . '[' . $id . ']';

	// div
	$div = array(
		'class'       => 'layout',
		'data-id'     => $id,
		'data-layout' => $layout['name'],
	);

	// clone
	if ( is_numeric( $i ) ) {

		$order = $i + 1;

	} else {

		$div['class'] .= ' acf-clone';

	}

	// display
	if ( $layout['display'] == 'table' ) {

		$el = 'td';

	}

	// title
	$title = $this->get_layout_title( $field, $layout, $i, $value );

	// remove row
	reset_rows();

	?>
<div <?php echo acf_esc_attr( $div ); ?>>

	<?php
	acf_hidden_input(
		array(
			'name'  => $prefix . '[acf_fc_layout]',
			'value' => $layout['name'],
		)
	);
	?>

	<div class="acf-fc-layout-handle" title="<?php _e( 'Drag to reorder', 'acf' ); ?>" data-name="collapse-layout"><?php echo acf_esc_html( $title ); ?></div>

	<div class="acf-fc-layout-controls">
<a class="acf-icon -plus small light acf-js-tooltip" href="#" data-name="add-layout" title="<?php _e( 'Add layout', 'acf' ); ?>"></a>
<a class="acf-icon -duplicate small light acf-js-tooltip" href="#" data-name="duplicate-layout" title="<?php _e( 'Duplicate layout', 'acf' ); ?>"></a>
<a class="acf-icon -minus small light acf-js-tooltip" href="#" data-name="remove-layout" title="<?php _e( 'Remove layout', 'acf' ); ?>"></a>
<a class="acf-icon -collapse small -clear acf-js-tooltip" href="#" data-name="collapse-layout" title="<?php _e( 'Click to toggle', 'acf' ); ?>"></a>
	</div>

	<?php if ( ! empty( $sub_fields ) ) : ?>

		<?php if ( $layout['display'] == 'table' ) : ?>
	<table class="acf-table">

<thead>
	<tr>
			<?php
			foreach ( $sub_fields as $sub_field ) :

				// Set prefix to generate correct "for" attribute on <label>.
				$sub_field['prefix'] = $prefix;

				// Prepare field (allow sub fields to be removed).
				$sub_field = acf_prepare_field( $sub_field );
				if ( ! $sub_field ) {
					continue;
				}

				// Define attrs.
				$attrs              = array();
				$attrs['class']     = 'acf-th';
				$attrs['data-name'] = $sub_field['_name'];
				$attrs['data-type'] = $sub_field['type'];
				$attrs['data-key']  = $sub_field['key'];

				if ( $sub_field['wrapper']['width'] ) {
					$attrs['data-width'] = $sub_field['wrapper']['width'];
					$attrs['style']      = 'width: ' . $sub_field['wrapper']['width'] . '%;';
				}

				?>
			<th <?php echo acf_esc_attrs( $attrs ); ?>>
				<?php acf_render_field_label( $sub_field ); ?>
				<?php acf_render_field_instructions( $sub_field ); ?>
			</th>
			<?php endforeach; ?>
	</tr>
</thead>

<tbody>
	<tr class="acf-row">
	<?php else : ?>
	<div class="acf-fields
<?php
if ( $layout['display'] == 'row' ) :
	?>
-left<?php endif; ?>">
	<?php endif; ?>

			<?php

			// loop though sub fields
			foreach ( $sub_fields as $sub_field ) {

				// add value
				if ( isset( $value[ $sub_field['key'] ] ) ) {

					// this is a normal value
					$sub_field['value'] = $value[ $sub_field['key'] ];

				} elseif ( isset( $sub_field['default_value'] ) ) {

					// no value, but this sub field has a default value
					$sub_field['value'] = $sub_field['default_value'];

				}

				// update prefix to allow for nested values
				$sub_field['prefix'] = $prefix;

				// render input
				acf_render_field_wrap( $sub_field, $el );

			}

			?>

		<?php if ( $layout['display'] == 'table' ) : ?>
	</tr>
</tbody>
	</table>
	<?php else : ?>
	</div>
	<?php endif; ?>

	<?php endif; ?>

</div>
	<?php

}