PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.8.3
Pods – Custom Content Types and Fields v3.2.8.3
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / Whatsit / Group.php
pods / src / Pods / Whatsit Last commit date
Storage 2 weeks ago Block.php 2 weeks ago Block_Collection.php 2 weeks ago Block_Field.php 2 weeks ago Field.php 2 weeks ago Group.php 2 weeks ago Legacy_Object.php 2 weeks ago Object_Field.php 2 weeks ago Page.php 2 weeks ago Pod.php 2 weeks ago Storage.php 2 weeks ago Store.php 2 weeks ago Template.php 2 weeks ago
Group.php
140 lines
1 <?php
2
3 namespace Pods\Whatsit;
4
5 use Exception;
6 use Pods\Whatsit;
7
8 /**
9 * Group class.
10 *
11 * @since 2.8.0
12 */
13 class Group extends Whatsit {
14
15 /**
16 * {@inheritdoc}
17 */
18 protected static $type = 'group';
19
20 /**
21 * {@inheritdoc}
22 */
23 public function get_args() {
24 $args = parent::get_args();
25
26 // Groups have no group.
27 unset( $args['group'] );
28
29 return $args;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public function get_fields( array $args = [] ) {
36 if ( [] === $this->_fields ) {
37 return [];
38 }
39
40 $api = pods_api();
41
42 $has_custom_args = ! empty( $args );
43
44 if ( null !== $this->_fields && ! $has_custom_args ) {
45 $objects = $this->maybe_get_objects_by_identifier( $this->_fields, $args );
46
47 if ( is_array( $objects ) ) {
48 $this->_fields = pods_clone_objects( $objects );
49
50 /** @var Field[] $objects */
51 return $objects;
52 }
53 }
54
55 $filtered_args = [
56 'parent' => $this->get_parent_id(),
57 'parent_id' => $this->get_parent_id(),
58 'parent_name' => $this->get_parent_name(),
59 'parent_identifier' => $this->get_parent_identifier(),
60 'group' => $this->get_name(),
61 'group_id' => $this->get_id(),
62 'group_name' => $this->get_name(),
63 'group_identifier' => $this->get_identifier(),
64 ];
65
66 if ( empty( $filtered_args['parent_id'] ) || empty( $filtered_args['group_id'] ) ) {
67 $filtered_args['bypass_post_type_find'] = true;
68 }
69
70 $filtered_args = array_filter( $filtered_args );
71
72 $args = array_merge( [
73 'orderby' => 'menu_order title',
74 'order' => 'ASC',
75 ], $filtered_args, $args );
76
77 try {
78 if ( empty( $args['parent_identifier'] ) && empty( $args['group_id'] ) ) {
79 throw new Exception( 'Invalid parent identifier for field lookup by group not by ID: ' . var_export( $args, true ) );
80 }
81
82 if ( ! empty( $args['object_type'] ) ) {
83 $objects = $api->_load_objects( $args );
84 } else {
85 $objects = $api->load_fields( $args );
86 }
87 } catch ( Exception $exception ) {
88 pods_debug_log( $exception );
89
90 $objects = [];
91 }
92
93 if ( ! $has_custom_args ) {
94 $this->_fields = pods_clone_objects( $objects );
95 }
96
97 return $objects;
98 }
99
100 /**
101 * {@inheritdoc}
102 */
103 public function get_groups( array $args = [] ) {
104 // Groups do not support groups.
105 return [];
106 }
107
108 /**
109 * {@inheritdoc}
110 */
111 public function get_arg( $arg, $default = null, $strict = false, $raw = false ) {
112 if ( $raw ) {
113 return parent::get_arg( $arg, $default, $strict, $raw );
114 }
115
116 $arg = (string) $arg;
117
118 $special_args = [
119 // Pod args.
120 'pod_id' => 'get_parent_id',
121 'pod' => 'get_parent_name',
122 'pod_name' => 'get_parent_name',
123 'pod_identifier' => 'get_parent_identifier',
124 'pod_label' => 'get_parent_label',
125 'pod_description' => 'get_parent_description',
126 'pod_object' => 'get_parent_object',
127 'pod_object_type' => 'get_parent_object_type',
128 'pod_object_storage_type' => 'get_parent_object_storage_type',
129 'pod_type' => 'get_parent_type',
130 ];
131
132 if ( isset( $special_args[ $arg ] ) ) {
133 return $this->{$special_args[ $arg ]}();
134 }
135
136 return parent::get_arg( $arg, $default );
137 }
138
139 }
140