Group.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace ACA\ACF\Configurable;
use ACA\ACF\Configurable;
use ACA\ACF\FieldFactory;
use ACA\ACF\GroupColumnFactory;
class Group implements Configurable {
/**
* @var FieldFactory
*/
private $field_factory;
public function __construct( FieldFactory $field_factory ) {
$this->field_factory = $field_factory;
}
private function get_group_field_key_by_type( $column_type ) {
$column_type = str_replace( GroupColumnFactory::GROUP_PREFIX, '', $column_type );
$parts = explode( '-', $column_type );
return $parts[0];
}
private function get_sub_field_key_by_type( $column_type ) {
$column_type = str_replace( GroupColumnFactory::GROUP_PREFIX, '', $column_type );
$parts = explode( '-', $column_type );
return $parts[1];
}
public function create( $column_type ) {
$group_field_key = $this->get_group_field_key_by_type( $column_type );
$sub_field_key = $this->get_sub_field_key_by_type( $column_type );
$group_settings = acf_get_field( $group_field_key );
$sub_field_settings = acf_get_field( $sub_field_key );
if ( ! $group_settings || ! $sub_field_settings ) {
return null;
}
$group_field = $this->field_factory->create( $group_settings );
$sub_field = $this->field_factory->create( $sub_field_settings );
$meta_key = sprintf( '%s_%s', $group_field->get_meta_key(), $sub_field->get_meta_key() );
return [
self::FIELD => $sub_field,
self::FIELD_TYPE => $sub_field->get_type(),
self::META_KEY => $meta_key,
self::FIELD_HASH => $sub_field_key,
];
}
}