| 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 |
|