PluginProbe
WPGraphQL / trunk
WPGraphQL vtrunk
2.22.3 2.22.2 2.22.1 2.22.0 2.21.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.15.0 2.14.1 2.14.0 2.13.0 2.2.0 2.3.0 2.3.3 2.3.6 2.3.8 2.5.0 2.5.1 2.5.2 2.5.3 All 177 releases
wp-graphql / src / Data / Loader / SettingGroupLoader.php

SettingGroupLoader.php in WPGraphQL trunk, at src/Data/Loader/SettingGroupLoader.php

48 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPGraphQL\Data\Loader;
3
4 use WPGraphQL\Data\DataSource;
5 use WPGraphQL\Model\SettingGroup;
6
7 /**
8 * Class SettingGroupLoader
9 *
10 * Loads settings groups (keyed by their normalized group key, e.g. "general",
11 * "permalink") from the normalized settings map and returns them as
12 * SettingGroup models.
13 *
14 * @package WPGraphQL\Data\Loader
15 */
16 class SettingGroupLoader extends AbstractDataLoader {
17
18 /**
19 * {@inheritDoc}
20 *
21 * @param array<string,array<string,mixed>> $entry The group's entries from the normalized settings map.
22 *
23 * @return \WPGraphQL\Model\SettingGroup
24 * @throws \Exception
25 */
26 protected function get_model( $entry, $key ) {
27 return new SettingGroup( (string) $key, $entry );
28 }
29
30 /**
31 * {@inheritDoc}
32 *
33 * @param string[] $keys Normalized settings group keys.
34 * @return array<string,array<string,array<string,mixed>>|null>
35 */
36 public function loadKeys( array $keys ) {
37 $groups = DataSource::get_allowed_settings_by_group( \WPGraphQL::get_type_registry() );
38
39 $loaded = [];
40
41 foreach ( $keys as $key ) {
42 $loaded[ $key ] = ! empty( $groups[ $key ] ) ? $groups[ $key ] : null;
43 }
44
45 return $loaded;
46 }
47 }
48