field = $field;
$this->layout = $layout;
$this->order = $order;
$this->value = $value;
$this->disabled = $disabled;
$this->renamed = $renamed;
}
/**
* Renders the layout.
*
* @since 6.5
*
* @return void
*/
public function render() {
$id = 'row-' . $this->order;
$class = 'layout';
if ( 'acfcloneindex' === $this->order ) {
$id = 'acfcloneindex';
$class .= ' acf-clone';
}
$this->prefix = $this->field['name'] . '[' . $id . ']';
$div_attrs = array(
'class' => $class,
'data-id' => $id,
'data-layout' => $this->layout['name'],
'data-label' => $this->layout['label'],
'data-min' => $this->layout['min'],
'data-max' => $this->layout['max'],
'data-enabled' => $this->disabled ? 0 : 1,
'data-renamed' => empty( $this->renamed ) ? 0 : 1,
);
echo '
'; // Layout wrapper div.
acf_hidden_input(
array(
'name' => $this->prefix . '[acf_fc_layout]',
'value' => $this->layout['name'],
)
);
acf_hidden_input(
array(
'class' => 'acf-fc-layout-disabled',
'name' => $this->prefix . '[acf_fc_layout_disabled]',
'value' => $this->disabled ? 1 : 0,
)
);
acf_hidden_input(
array(
'class' => 'acf-fc-layout-custom-label',
'name' => $this->prefix . '[acf_fc_layout_custom_label]',
'value' => $this->renamed,
)
);
$this->action_buttons();
if ( ! empty( $this->layout['sub_fields'] ) ) {
if ( 'table' === $this->layout['display'] ) {
$this->render_as_table();
} else {
$this->render_as_div();
}
}
echo '
'; // End layout wrapper div.
}
/**
* Renders a layout as a table.
*
* @since 6.5
*
* @return void
*/
private function render_as_table() {
$sub_fields = $this->layout['sub_fields'];
?>
.
$sub_field['prefix'] = $this->prefix;
// Prepare field (allow sub fields to be removed).
$sub_field = acf_prepare_field( $sub_field );
if ( ! $sub_field ) {
continue;
}
$th_attrs = array(
'class' => 'acf-th',
'data-name' => $sub_field['_name'],
'data-type' => $sub_field['type'],
'data-key' => $sub_field['key'],
);
if ( $sub_field['wrapper']['width'] ) {
$th_attrs['data-width'] = $sub_field['wrapper']['width'];
$th_attrs['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;';
}
echo '| ';
acf_render_field_label( $sub_field );
acf_render_field_instructions( $sub_field );
echo ' | ';
}
?>
sub_fields(); ?>
layout['display'] ) {
$class .= ' -left';
}
echo '';
$this->sub_fields();
echo '
';
}
/**
* Renders the layout actions (Add, Duplicate, Rename).
*
* @since 6.5
*
* @return void
*/
private function action_buttons() {
$title = $this->get_title();
$order = is_numeric( $this->order ) ? $this->order + 1 : 0;
?>
renamed ) ? esc_html( $this->renamed ) : $title; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped earlier in function. ?>
()
layout['sub_fields'] as $sub_field ) {
// add value
if ( isset( $this->value[ $sub_field['key'] ] ) ) {
// this is a normal value
$sub_field['value'] = $this->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'] = $this->prefix;
// Render the input.
$el = 'table' === $this->layout['display'] ? 'td' : 'div';
acf_render_field_wrap( $sub_field, $el );
}
}
/**
* Returns the filtered layout title.
*
* @since 6.5
*
* @return string
*/
public function get_title() {
$rows = array();
$rows[ $this->order ] = $this->value;
acf_add_loop(
array(
'selector' => $this->field['name'],
'name' => $this->field['name'],
'value' => $rows,
'field' => $this->field,
'i' => $this->order,
'post_id' => 0,
)
);
// Make the title filterable.
$title = esc_html( $this->layout['label'] );
$title = apply_filters( 'acf/fields/flexible_content/layout_title', $title, $this->field, $this->layout, $this->order );
$title = apply_filters( 'acf/fields/flexible_content/layout_title/name=' . $this->field['_name'], $title, $this->field, $this->layout, $this->order );
$title = apply_filters( 'acf/fields/flexible_content/layout_title/key=' . $this->field['key'], $title, $this->field, $this->layout, $this->order );
$title = acf_esc_html( $title );
acf_remove_loop();
reset_rows(); // TODO: Make sure this is actually where this should go if needed at all.
return $title;
}
}