Skip to content

Instantly share code, notes, and snippets.

@DGStefan
Created April 21, 2022 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DGStefan/b7e69249ed510728ba718c190511f8c3 to your computer and use it in GitHub Desktop.
Save DGStefan/b7e69249ed510728ba718c190511f8c3 to your computer and use it in GitHub Desktop.
Group fix
<?php
namespace ACA\ACF;
class GroupColumnFactory {
const GROUP_PREFIX = 'acfgroup__';
/**
* @var ColumnFactory
*/
private $column_factory;
public function __construct( ColumnFactory $column_factory ) {
$this->column_factory = $column_factory;
}
/**
* @param array $settings
*
* @return Column|null
*/
public function create( array $settings ) {
$parts = explode( '-', $settings['key'] );
$group_field = acf_get_field( $parts[0] );
$sub_field = acf_get_field( $parts[1] );
if ( ! isset( $sub_field['type'] ) ) {
return null;
}
// Add prefix for the correct column config
$sub_field['key'] = self::GROUP_PREFIX . $settings['key'];
// Add group label
$sub_field['label'] = sprintf( '%s - %s', $group_field['label'], $sub_field['label'] );
if ( $sub_field['type'] === 'group' ) {
return null;
}
return $this->column_factory->create( $sub_field );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment