acf_field_flexible_content::format_value_for_rest()
Apply basic formatting to prepare the value for default REST output.
Метод класса: acf_field_flexible_content{}
Хуков нет.
Возвращает
Массив|Разное
.
Использование
$acf_field_flexible_content = new acf_field_flexible_content(); $acf_field_flexible_content->format_value_for_rest( $value, $post_id, $field );
- $value(разное) (обязательный)
- -
- $post_id(int|строка) (обязательный)
- -
- $field(массив) (обязательный)
- -
Код acf_field_flexible_content::format_value_for_rest() acf field flexible content::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['layouts'] ) ) { return null; } // Create a map of layout sub fields mapped to layout names. foreach ( $field['layouts'] as $layout ) { $layouts[ $layout['name'] ] = $layout['sub_fields']; } // Loop through each layout and within that, each sub field to process sub fields individually. foreach ( $value as &$layout ) { $name = $layout['acf_fc_layout']; if ( empty( $layouts[ $name ] ) ) { continue; } foreach ( $layouts[ $name ] 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 $layout and format it. $sub_value = acf_extract_var( $layout, $sub_field['key'] ); $sub_value = acf_format_value_for_rest( $sub_value, $post_id, $sub_field ); // Add the sub field value back to the $layout but mapped to the field name instead // of the key reference. $layout[ $sub_field['name'] ] = $sub_value; } } return $value; }