Aggregate.php
4 days ago
BeaverBuilderGroups.php
4 days ago
BuddyPressGroups.php
4 days ago
DefaultGroups.php
4 days ago
EventsCalendarGroups.php
4 days ago
GravityFormsGroups.php
4 days ago
JetEngineGroups.php
4 days ago
MediaLibraryAssistantGroups.php
4 days ago
MetaBoxGroups.php
4 days ago
WooCommerceGroups.php
4 days ago
Aggregate.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Admin\MenuGroupFactory; |
| 6 | |
| 7 | use AC\Admin\MenuGroupFactory; |
| 8 | use AC\Admin\Type\MenuGroup; |
| 9 | use AC\TableScreen; |
| 10 | |
| 11 | class Aggregate implements MenuGroupFactory |
| 12 | { |
| 13 | /** |
| 14 | * @var array{factory: MenuGroupFactory, priority: int}[] |
| 15 | */ |
| 16 | private static array $factories = []; |
| 17 | |
| 18 | public static function add(MenuGroupFactory $factory, int $priority = 10): void |
| 19 | { |
| 20 | self::$factories[] = [ |
| 21 | 'factory' => $factory, |
| 22 | 'priority' => $priority, |
| 23 | ]; |
| 24 | |
| 25 | usort(self::$factories, static function (array $a, array $b): int { |
| 26 | return $a['priority'] - $b['priority']; |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | public function create(TableScreen $table_screen): MenuGroup |
| 31 | { |
| 32 | foreach (self::$factories as $entry) { |
| 33 | $group = $entry['factory']->create($table_screen); |
| 34 | |
| 35 | if ($group) { |
| 36 | return $group; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return new MenuGroup('other', __('Other', 'codepress-admin-columns')); |
| 41 | } |
| 42 | |
| 43 | } |
| 44 |