Created
April 21, 2022 07:47
-
-
Save DGStefan/b7e69249ed510728ba718c190511f8c3 to your computer and use it in GitHub Desktop.
Group fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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