acf_field_flexible_content::render_field
Create the HTML interface for your field
Метод класса: acf_field_flexible_content{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$acf_field_flexible_content = new acf_field_flexible_content(); $acf_field_flexible_content->render_field( $field );
- $field(обязательный)
- .
Список изменений
| С версии 3.6 | Введена. |
Код acf_field_flexible_content::render_field() acf field flexible content::render field ACF 6.4.2
<?php
function render_field( $field ) {
// defaults
if ( empty( $field['button_label'] ) ) {
$field['button_label'] = $this->defaults['button_label'];
}
// sort layouts into names
$layouts = array();
foreach ( $field['layouts'] as $k => $layout ) {
$layouts[ $layout['name'] ] = $layout;
}
// vars
$div = array(
'class' => 'acf-flexible-content',
'data-min' => $field['min'],
'data-max' => $field['max'],
);
// empty
if ( empty( $field['value'] ) ) {
$div['class'] .= ' -empty';
}
// no value message
// translators: %s the button label used for adding a new layout.
$no_value_message = __( 'Click the "%s" button below to start creating your layout', 'acf' );
$no_value_message = apply_filters( 'acf/fields/flexible_content/no_value_message', $no_value_message, $field );
$no_value_message = sprintf( $no_value_message, $field['button_label'] );
?>
<div <?php echo acf_esc_attrs( $div ); ?>>
<?php acf_hidden_input( array( 'name' => $field['name'] ) ); ?>
<div class="no-value-message">
<?php echo acf_esc_html( $no_value_message ); ?>
</div>
<div class="clones">
<?php foreach ( $layouts as $layout ) : ?>
<?php $this->render_layout( $field, $layout, 'acfcloneindex', array() ); ?>
<?php endforeach; ?>
</div>
<div class="values">
<?php
if ( ! empty( $field['value'] ) ) {
foreach ( $field['value'] as $i => $value ) {
// validate
if ( ! is_array( $value ) ) {
continue;
}
if ( empty( $layouts[ $value['acf_fc_layout'] ] ) ) {
continue;
}
// render
$this->render_layout( $field, $layouts[ $value['acf_fc_layout'] ], $i, $value );
}
}
?>
</div>
<div class="acf-actions">
<a class="acf-button button button-primary" href="#" data-name="add-layout"><?php echo acf_esc_html( $field['button_label'] ); ?></a>
</div>
<?php
echo '<script type="text-html" class="tmpl-popup"><ul>';
foreach ( $layouts as $layout ) {
$atts = array(
'href' => '#',
'data-layout' => $layout['name'],
'data-min' => $layout['min'],
'data-max' => $layout['max'],
);
printf( '<li><a %s>%s</a></li>', acf_esc_attrs( $atts ), acf_esc_html( $layout['label'] ) );
}
echo '</ul></script>';
?>
</div>
<?php
}