acf_field_flexible_content::format_valuepublicACF 3.6

This filter is appied to the $value after it is loaded from the db and before it is returned to the template

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

Хуков нет.

Возвращает

Разное. $value The modified value.

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

$acf_field_flexible_content = new acf_field_flexible_content();
$acf_field_flexible_content->format_value( $value, $post_id, $field, $escape_html );
$value(разное) (обязательный)
The value which was loaded from the database.
$post_id(разное) (обязательный)
The $post_id from which the value was loaded.
$field(массив) (обязательный)
The field array holding all the field options.
$escape_html(true|false)
Should the field return a HTML safe formatted value.
По умолчанию: false

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

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

Код acf_field_flexible_content::format_value() ACF 6.4.2

public function format_value( $value, $post_id, $field, $escape_html = false ) {

	// bail early if no value
	if ( empty( $value ) || empty( $field['layouts'] ) ) {
		return false;
	}

	// sort layouts into names
	$layouts = array();
	foreach ( $field['layouts'] as $k => $layout ) {
		$layouts[ $layout['name'] ] = $layout['sub_fields'];
	}

	// loop over rows
	foreach ( array_keys( $value ) as $i ) {

		// get layout name
		$l = $value[ $i ]['acf_fc_layout'];

		// bail early if layout deosnt exist
		if ( empty( $layouts[ $l ] ) ) {
			continue;
		}

		// get layout
		$layout = $layouts[ $l ];

		// loop through sub fields
		foreach ( array_keys( $layout ) as $j ) {

			// get sub field
			$sub_field = $layout[ $j ];

			// bail early if no name (tab)
			if ( acf_is_empty( $sub_field['name'] ) ) {
				continue;
			}

			// extract value
			$sub_value = acf_extract_var( $value[ $i ], $sub_field['key'] );

			// update $sub_field name
			$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";

			// format value
			$sub_value = acf_format_value( $sub_value, $post_id, $sub_field, $escape_html );

			// append to $row
			$value[ $i ][ $sub_field['_name'] ] = $sub_value;
		}
	}

	// return
	return $value;
}