PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.3
Yatra – Travel Booking & Tour Operator Software v3.0.3
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Providers / BlockServiceProvider.php

BlockServiceProvider.php in Yatra – Travel Booking & Tour Operator Software 3.0.3, at app/Providers/BlockServiceProvider.php

77 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Providers;
6
7 use Yatra\Blocks\TourBlock;
8 use Yatra\Blocks\ActivityBlock;
9 use Yatra\Blocks\DestinationBlock;
10 use Yatra\Blocks\TripCategoryBlock;
11 use Yatra\Core\Container;
12 use Yatra\Core\ServiceProvider;
13
14 /**
15 * Block Service Provider
16 *
17 * Registers all Gutenberg blocks for Yatra
18 * Maintains backward compatibility with old plugin blocks
19 *
20 * @package Yatra\Providers
21 * @since 3.0.0
22 */
23 class BlockServiceProvider extends ServiceProvider
24 {
25 public function __construct(Container $container)
26 {
27 parent::__construct($container);
28 }
29
30 /**
31 * Register blocks
32 */
33 public function register(): void
34 {
35 // Priority 100 so other plugins (or old stubs) register first; we reclaim + register full assets last.
36 if (did_action('init')) {
37 $this->registerBlocksOnInit();
38 } else {
39 add_action('init', [$this, 'registerBlocksOnInit'], 100);
40 }
41
42 // Register Yatra block category
43 add_filter('block_categories_all', [$this, 'registerBlockCategory'], 10, 2);
44 }
45
46 /**
47 * Register blocks on init hook
48 */
49 public function registerBlocksOnInit(): void
50 {
51 // Initialize all blocks
52 new TourBlock();
53 new ActivityBlock();
54 new DestinationBlock();
55 new TripCategoryBlock();
56 }
57
58 /**
59 * Register Yatra block category
60 *
61 * @param array $categories Existing block categories
62 * @param \WP_Block_Editor_Context $context Block editor context
63 * @return array Modified categories
64 */
65 public function registerBlockCategory(array $categories, \WP_Block_Editor_Context $context): array
66 {
67 // Add Yatra category at the beginning
68 array_unshift($categories, [
69 'slug' => 'yatra',
70 'title' => __('Yatra', 'yatra'),
71 'icon' => '<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M12 2L2 7v10c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V7l-10-5z" fill="currentColor"/></svg>',
72 ]);
73
74 return $categories;
75 }
76 }
77