acf_field_repeater::format_value_for_rest()publicACF 1.0

Apply basic formatting to prepare the value for default REST output.

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

Хуков нет.

Возвращает

Массив|Разное.

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

$acf_field_repeater = new acf_field_repeater();
$acf_field_repeater->format_value_for_rest( $value, $post_id, $field );
$value(разное) (обязательный)
-
$post_id(int|строка) (обязательный)
-
$field(массив) (обязательный)
-

Код acf_field_repeater::format_value_for_rest() ACF 6.0.4

public function format_value_for_rest( $value, $post_id, array $field ) {
	if ( empty( $value ) || ! is_array( $value ) || empty( $field['sub_fields'] ) ) {
		return null;
	}

	// Loop through each row and within that, each sub field to process sub fields individually.
	foreach ( $value as &$row ) {
		foreach ( $field['sub_fields'] as $sub_field ) {

			// Bail early if the field has no name (tab).
			if ( acf_is_empty( $sub_field['name'] ) ) {
				continue;
			}

			// Extract the sub field 'field_key'=>'value' pair from the $row and format it.
			$sub_value = acf_extract_var( $row, $sub_field['key'] );
			$sub_value = acf_format_value_for_rest( $sub_value, $post_id, $sub_field );

			// Add the sub field value back to the $row but mapped to the field name instead
			// of the key reference.
			$row[ $sub_field['name'] ] = $sub_value;
		}
	}

	return $value;
}