Skip to content

Revert "Implement repeatable array field support"#39

Merged
erseco merged 1 commit intomainfrom
revert-37-feature/add-array-fields-for-annexes-support-cmdtk9
Oct 14, 2025
Merged

Revert "Implement repeatable array field support"#39
erseco merged 1 commit intomainfrom
revert-37-feature/add-array-fields-for-annexes-support-cmdtk9

Conversation

@erseco
Copy link
Copy Markdown
Collaborator

@erseco erseco commented Oct 14, 2025

Reverts #37

@erseco erseco merged commit cd986ab into main Oct 14, 2025
2 of 3 checks passed
Comment on lines +317 to +360
private function build_schema_from_fields( $fields ) {
$schema = array();
foreach ( $fields as $field ) {
$placeholder = '';
$slug = '';
$label = '';
$data_type = 'text';

if ( is_array( $field ) ) {
$placeholder = isset( $field['placeholder'] ) ? $this->sanitize_placeholder_name( $field['placeholder'] ) : '';
$slug = isset( $field['slug'] ) ? sanitize_key( $field['slug'] ) : '';
if ( '' === $slug && '' !== $placeholder ) {
$slug = sanitize_key( str_replace( array( '.', ':' ), '_', strtolower( $placeholder ) ) );
}
$label = isset( $field['label'] ) ? sanitize_text_field( $field['label'] ) : '';
$data_type = isset( $field['data_type'] ) ? sanitize_key( $field['data_type'] ) : 'text';
} else {
$placeholder = is_string( $field ) ? $this->sanitize_placeholder_name( $field ) : '';
$slug = sanitize_key( $placeholder );
}

if ( '' === $slug ) {
continue;
}
if ( '' === $label ) {
$label = $this->humanize_slug( '' !== $placeholder ? $placeholder : $slug );
}
if ( ! in_array( $data_type, array( 'text', 'number', 'boolean', 'date' ), true ) ) {
$data_type = 'text';
}
if ( '' === $placeholder ) {
$placeholder = $slug;
}

$schema[] = array(
'slug' => $slug,
'label' => $label,
'type' => 'textarea',
'placeholder' => $placeholder,
'data_type' => $data_type,
);
}
return $schema;
}

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method build_schema_from_fields() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
Comment on lines +317 to +360
private function build_schema_from_fields( $fields ) {
$schema = array();
foreach ( $fields as $field ) {
$placeholder = '';
$slug = '';
$label = '';
$data_type = 'text';

if ( is_array( $field ) ) {
$placeholder = isset( $field['placeholder'] ) ? $this->sanitize_placeholder_name( $field['placeholder'] ) : '';
$slug = isset( $field['slug'] ) ? sanitize_key( $field['slug'] ) : '';
if ( '' === $slug && '' !== $placeholder ) {
$slug = sanitize_key( str_replace( array( '.', ':' ), '_', strtolower( $placeholder ) ) );
}
$label = isset( $field['label'] ) ? sanitize_text_field( $field['label'] ) : '';
$data_type = isset( $field['data_type'] ) ? sanitize_key( $field['data_type'] ) : 'text';
} else {
$placeholder = is_string( $field ) ? $this->sanitize_placeholder_name( $field ) : '';
$slug = sanitize_key( $placeholder );
}

if ( '' === $slug ) {
continue;
}
if ( '' === $label ) {
$label = $this->humanize_slug( '' !== $placeholder ? $placeholder : $slug );
}
if ( ! in_array( $data_type, array( 'text', 'number', 'boolean', 'date' ), true ) ) {
$data_type = 'text';
}
if ( '' === $placeholder ) {
$placeholder = $slug;
}

$schema[] = array(
'slug' => $slug,
'label' => $label,
'type' => 'textarea',
'placeholder' => $placeholder,
'data_type' => $data_type,
);
}
return $schema;
}

Check warning

Code scanning / PHPMD

Code Size Rules: NPathComplexity Warning

The method build_schema_from_fields() has an NPath complexity of 1201. The configured NPath complexity threshold is 200.
Comment on lines +260 to +305
public function revision_field_annexes( $value, $revision = null ) {
// Resolve revision ID similar to revision_field_value.
$rev_id = 0;
$args = func_get_args();
foreach ( $args as $arg ) {
if ( is_object( $arg ) && isset( $arg->ID ) ) {
$rev_id = intval( $arg->ID );
break;
}
if ( is_array( $arg ) && isset( $arg['ID'] ) && is_numeric( $arg['ID'] ) ) {
$maybe = get_post( intval( $arg['ID'] ) );
if ( $maybe && 'revision' === $maybe->post_type ) {
$rev_id = intval( $maybe->ID );
break;
}
}
if ( is_numeric( $arg ) ) {
$maybe = get_post( intval( $arg ) );
if ( $maybe && 'revision' === $maybe->post_type ) {
$rev_id = intval( $maybe->ID );
break;
}
}
}
if ( $rev_id <= 0 ) {
return '';
}
$annexes = get_metadata( 'post', $rev_id, 'resolate_annexes', true );
if ( ! is_array( $annexes ) || empty( $annexes ) ) {
return '';
}
$lines = array();
foreach ( $annexes as $i => $anx ) {
$title = isset( $anx['title'] ) ? (string) $anx['title'] : '';
$text = isset( $anx['text'] ) ? (string) $anx['text'] : '';
$lines[] = sprintf(
/* translators: 1: annex number, 2: annex title */
__( 'Annex %1$d: %2$s', 'resolate' ),
( $i + 1 ),
$title
);
$lines[] = $this->normalize_html_for_diff( $text );
$lines[] = str_repeat( '-', 40 );
}
return implode( "\n", $lines );
}

Check warning

Code scanning / PHPMD

Code Size Rules: CyclomaticComplexity Warning

The method revision_field_annexes() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10.
Comment on lines +260 to +305
public function revision_field_annexes( $value, $revision = null ) {
// Resolve revision ID similar to revision_field_value.
$rev_id = 0;
$args = func_get_args();
foreach ( $args as $arg ) {
if ( is_object( $arg ) && isset( $arg->ID ) ) {
$rev_id = intval( $arg->ID );
break;
}
if ( is_array( $arg ) && isset( $arg['ID'] ) && is_numeric( $arg['ID'] ) ) {
$maybe = get_post( intval( $arg['ID'] ) );
if ( $maybe && 'revision' === $maybe->post_type ) {
$rev_id = intval( $maybe->ID );
break;
}
}
if ( is_numeric( $arg ) ) {
$maybe = get_post( intval( $arg ) );
if ( $maybe && 'revision' === $maybe->post_type ) {
$rev_id = intval( $maybe->ID );
break;
}
}
}
if ( $rev_id <= 0 ) {
return '';
}
$annexes = get_metadata( 'post', $rev_id, 'resolate_annexes', true );
if ( ! is_array( $annexes ) || empty( $annexes ) ) {
return '';
}
$lines = array();
foreach ( $annexes as $i => $anx ) {
$title = isset( $anx['title'] ) ? (string) $anx['title'] : '';
$text = isset( $anx['text'] ) ? (string) $anx['text'] : '';
$lines[] = sprintf(
/* translators: 1: annex number, 2: annex title */
__( 'Annex %1$d: %2$s', 'resolate' ),
( $i + 1 ),
$title
);
$lines[] = $this->normalize_html_for_diff( $text );
$lines[] = str_repeat( '-', 40 );
}
return implode( "\n", $lines );
}

Check warning

Code scanning / PHPMD

Code Size Rules: NPathComplexity Warning

The method revision_field_annexes() has an NPath complexity of 2190. The configured NPath complexity threshold is 200.
@erseco erseco deleted the revert-37-feature/add-array-fields-for-annexes-support-cmdtk9 branch November 30, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants