PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / ColumnFactory / CustomFieldFactory.php
codepress-admin-columns / classes / ColumnFactory Last commit date
Comment 2 days ago Media 2 days ago Post 2 days ago User 2 days ago ActionsFactory.php 2 days ago CustomFieldFactory.php 2 days ago IntegrationPlaceholder.php 2 days ago OriginalFactory.php 2 days ago
CustomFieldFactory.php
146 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\ColumnFactory;
6
7 use AC;
8 use AC\Column\BaseColumnFactory;
9 use AC\Column\Context;
10 use AC\Column\CustomFieldContext;
11 use AC\Formatter\Aggregate;
12 use AC\FormatterCollection;
13 use AC\Setting\ComponentCollection;
14 use AC\Setting\ComponentFactory;
15 use AC\Setting\ComponentFactory\ColumnInfo;
16 use AC\Setting\ComponentFactory\FieldType;
17 use AC\Setting\Config;
18 use AC\Setting\DefaultSettingsBuilder;
19 use AC\Type\TableScreenContext;
20
21 class CustomFieldFactory extends BaseColumnFactory
22 {
23 private ComponentFactory\CustomFieldFactory $custom_field_factory;
24
25 private FieldType $field_type;
26
27 private TableScreenContext $table_context;
28
29 private ComponentFactory\BeforeAfter $before_after;
30
31 private ComponentFactory\Pro\TogglePromotionFactory $pro_promotion_factory;
32
33 public function __construct(
34 DefaultSettingsBuilder $default_settings_builder,
35 ComponentFactory\CustomFieldFactory $custom_field_factory,
36 TableScreenContext $table_context,
37 FieldType $field_type,
38 ComponentFactory\BeforeAfter $before_after,
39 ComponentFactory\Pro\TogglePromotionFactory $pro_promotion_factory
40 ) {
41 parent::__construct(
42 $default_settings_builder
43 );
44
45 $this->custom_field_factory = $custom_field_factory;
46 $this->field_type = $field_type;
47 $this->table_context = $table_context;
48 $this->before_after = $before_after;
49 $this->pro_promotion_factory = $pro_promotion_factory;
50 }
51
52 protected function get_settings(Config $config): ComponentCollection
53 {
54 $items = [];
55
56 $meta_key = $config->get('field', '');
57
58 if ('' !== $meta_key) {
59 $items[] = ['label' => __('Meta Key', 'codepress-admin-columns'), 'value' => $meta_key];
60 }
61
62 $components = [
63 $this->custom_field_factory->create($this->table_context)->create($config),
64 $this->field_type->create($config),
65 ];
66
67 if (! empty($items)) {
68 $components[] = (new ColumnInfo($items))->create($config);
69 }
70
71 $components[] = $this->before_after->create($config);
72 $components[] = $this->pro_promotion_factory->create(__('Enable Editing', 'codepress-admin-columns'), 'editing')->create($config);
73 $components[] = $this->pro_promotion_factory->create(__('Enable Bulk Editing', 'codepress-admin-columns'), 'bulk-edit')->create($config);
74 $components[] = $this->pro_promotion_factory->create(__('Enable Export', 'codepress-admin-columns'), 'export')->create($config);
75 $components[] = $this->pro_promotion_factory->create(__('Enable Smart Filtering', 'codepress-admin-columns'), 'search')->create($config);
76 $components[] = $this->pro_promotion_factory->create(__('Enable Filtering', 'codepress-admin-columns'), 'filter')->create($config);
77 $components[] = $this->pro_promotion_factory->create(__('Enable Sorting', 'codepress-admin-columns'), 'sorting')->create($config);
78
79 return new ComponentCollection($components);
80 }
81
82 public function get_column_type(): string
83 {
84 return 'column-meta';
85 }
86
87 public function get_label(): string
88 {
89 return __('Custom Field', 'codepress-admin-columns');
90 }
91
92 private function get_meta_key(Config $config): string
93 {
94 return (string)$config->get('field', '');
95 }
96
97 private function get_field_type(Config $config): string
98 {
99 return (string)$config->get('field_type', '');
100 }
101
102 protected function get_context(Config $config): Context
103 {
104 return new CustomFieldContext(
105 $config,
106 $this->get_label(),
107 $this->get_field_type($config),
108 $this->get_meta_key($config),
109 $this->table_context
110 );
111 }
112
113 protected function get_formatters(Config $config): FormatterCollection
114 {
115 $formatters = parent::get_formatters($config);
116
117 switch ($this->get_field_type($config)) {
118 case FieldType::TYPE_COUNT:
119 return $formatters->prepend(
120 Aggregate::from_array([
121 new AC\Formatter\MetaValueCollection(
122 $this->table_context->get_meta_type(),
123 $this->get_meta_key($config)
124 ),
125 new AC\Formatter\Count(),
126 ])
127 );
128 case FieldType::TYPE_META_COUNT:
129 return $formatters->prepend(
130 Aggregate::from_array([
131 new AC\Formatter\MetaCollection(
132 $this->table_context->get_meta_type(),
133 $this->get_meta_key($config)
134 ),
135 new AC\Formatter\Count(),
136 ])
137 );
138 }
139
140 return $formatters->prepend(
141 new AC\Formatter\Meta($this->table_context->get_meta_type(), $this->get_meta_key($config))
142 );
143 }
144
145 }
146