name = esc_html__( 'Field Group', 'forminator' );
}
/**
* Field defaults
*
* @return array
*/
public function defaults() {
return array(
'field_label' => esc_html__( 'Field Group', 'forminator' ),
'is_repeater' => 'true',
);
}
/**
* Autofill Setting
*
* @param array $settings Field settings.
*
* @return array
*/
public function autofill_settings( $settings = array() ) {
// Unsupported Autofill.
$autofill_settings = array();
return $autofill_settings;
}
/**
* Field front-end markup
*
* @param array $field Field.
* @param Forminator_Render_Form $views_obj Forminator_Render_Form object.
*
* @return mixed
*/
public function markup( $field, $views_obj ) {
$name = self::get_property( 'element_id', $field );
$wrappers = $views_obj::get_grouped_wrappers( $name );
// Don't render field group if it has no fields inside.
if ( empty( $wrappers ) ) {
return '';
}
$options = self::prepare_field_options( $field );
$settings = $views_obj->model->settings;
$html = '';
if ( ! empty( $field['field_label'] ) ) {
$html .= sprintf(
'',
self::convert_markdown( esc_html( $field['field_label'] ) )
);
}
$description = self::get_property( 'description', $field );
$descr_position = self::get_description_position( $field, $settings );
if ( ! empty( $description ) && 'above' === $descr_position ) {
$html .= apply_filters(
'forminator_field_description',
sprintf(
'%s',
self::convert_markdown( self::esc_description( $description, $name ) )
),
$description,
$name,
$descr_position
);
}
$html .= '
';
if ( 'above' !== $descr_position ) {
$html .= apply_filters(
'forminator_field_description',
self::get_description( $description, $name, $descr_position ),
$description,
$name,
$descr_position
);
}
return $html;
}
/**
* Prepare field options
*
* @param array $field Field options.
* @return array
*/
private static function prepare_field_options( $field ) {
$min_limit_type = empty( $field['min_limit_type'] ) || 'variable' !== $field['min_limit_type'] ? 'custom' : $field['min_limit_type'];
$max_limit_type = empty( $field['max_limit_type'] ) || 'variable' !== $field['max_limit_type'] ? 'custom' : $field['max_limit_type'];
if ( 'custom' === $min_limit_type ) {
$min = empty( $field['min_limit'] ) || 1 > intval( $field['min_limit'] ) ? 1 : intval( $field['min_limit'] );
} else {
$min = empty( $field['min_limit_field'] ) ? 1 : $field['min_limit_field'];
}
if ( 'custom' === $max_limit_type ) {
$max = empty( $field['max_limit'] ) || 1 > intval( $field['max_limit'] ) ? PHP_INT_MAX : intval( $field['max_limit'] );
} else {
$max = empty( $field['max_limit_field'] ) ? PHP_INT_MAX : $field['max_limit_field'];
}
return array(
'is_repeater' => empty( $field['is_repeater'] ) || 'true' === $field['is_repeater'],
'min_type' => $min_limit_type,
'max_type' => $max_limit_type,
'min' => $min,
'max' => $max,
'add_text' => empty( $field['add_action_text'] ) ? esc_html__( 'Add item', 'forminator' ) : $field['add_action_text'],
'remove_text' => empty( $field['remove_action_text'] ) ? esc_html__( 'Remove item', 'forminator' ) : $field['remove_action_text'],
'action_element_type' => empty( $field['action_element_type'] ) ? 'button' : $field['action_element_type'],
);
}
/**
* Get Repeater actions
*
* @param array $options Field options.
* @return string
*/
private static function render_action_buttons( $options ) {
$html = '';
return $html;
}
}