<?php

/***************************************** for textarea ****************************************************************************/
//var_dump($field->type);
if ( in_array( $field->type, $textarea_fields ) ) {

	$divs = $dom->getElementsByTagName( 'div' );

	$contains_error = false;
	foreach ( $divs as $div ) {
		$current_div_classes = $div->getAttribute( 'class' );
		if ( strpos( $current_div_classes, 'validation_message' ) !== false ) {
			$contains_error = true;
			$div->setAttribute( 'class', $div->getAttribute( 'class' ) . ' invalid-feedback' );
		}
	}

	foreach ( $divs as $div ) {
		$contains_placeholder = false;
		$add_label_classes = '';
		$div_classes = $div->getAttribute( 'class' );
		if ( strpos( $div_classes, 'ginput_container_textarea' ) !== false || strpos( $div_classes, 'ginput_container_post_excerpt' ) !== false ) {
				// if ( $contains_error ) {   2
	 		// 	$div_classes .= ' mdc-text-field--invalid';
			// }
			$div->setAttribute( 'class', $div_classes . ' form-group' );

			$textareas = $div->getElementsByTagName( 'textarea' );

			foreach ( $textareas as $textarea ) {

				$textarea->setAttribute( 'class',
					$textarea->getAttribute( 'class' ) . ' form-control' );
					if ( $contains_error ) {
						$textarea->setAttribute( 'class',
					$textarea->getAttribute( 'class' ) . ' is-invalid' ); //3
					}

			}
		}

	}

	$content = utf8_decode($dom->saveHTML($dom->documentElement));
}
