PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.13
Yatra – Travel Booking & Tour Operator Software v3.0.13
3.0.15 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 All 83 releases
yatra / app / Blocks / TripCategoryBlock.php

TripCategoryBlock.php in Yatra – Travel Booking & Tour Operator Software 3.0.13, at app/Blocks/TripCategoryBlock.php

106 lines 3.8 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\Blocks;
6
7 use Yatra\Providers\FrontendAssetsProvider;
8 use Yatra\Services\BlockDataService;
9
10 /**
11 * Gutenberg block: trip category grid (same UI as destination block).
12 */
13 class TripCategoryBlock
14 {
15 public function __construct()
16 {
17 $this->register();
18 }
19
20 /**
21 * @param array<string, mixed> $attributes
22 */
23 public function renderCallback(array $attributes, string $content): string
24 {
25 FrontendAssetsProvider::registerCoreFrontendStylesheets();
26 wp_enqueue_style('yatra-destination-shortcode');
27
28 return BlockDataService::renderTripCategoryBlock($attributes);
29 }
30
31 public function register(): void
32 {
33 BlockEditorScript::reclaimBlockName('yatra/trip-category');
34
35 $editorDeps = BlockEditorScript::editorDependencies();
36 if (! BlockEditorScript::register('yatra-trip-category-block-editor', 'trip-category', $editorDeps)) {
37 return;
38 }
39
40 FrontendAssetsProvider::registerCoreFrontendStylesheets();
41
42 wp_register_style(
43 'yatra-listing',
44 \YATRA_PLUGIN_URL . 'assets/css/listing.css',
45 [],
46 YATRA_VERSION
47 );
48
49 $destinationShortcodeCss = \YATRA_PLUGIN_PATH . 'assets/css/shortcodes/destination-shortcode.css';
50 $destinationShortcodeVer = is_readable($destinationShortcodeCss) ? YATRA_VERSION . '.' . filemtime($destinationShortcodeCss) : YATRA_VERSION;
51 wp_register_style(
52 'yatra-destination-shortcode',
53 \YATRA_PLUGIN_URL . 'assets/css/shortcodes/destination-shortcode.css',
54 FrontendAssetsProvider::shortcodeStyleDependencies(),
55 $destinationShortcodeVer
56 );
57
58 wp_register_script(
59 'yatra-trip-category-shortcode',
60 \YATRA_PLUGIN_URL . 'assets/js/trip-category-shortcode.js',
61 ['jquery'],
62 YATRA_VERSION,
63 true
64 );
65
66 $block = register_block_type_from_metadata(
67 BlockEditorScript::blockJsonPath('trip-category'),
68 [
69 'render_callback' => [$this, 'renderCallback'],
70 'editor_style' => ['yatra-listing', 'yatra-destination-shortcode'],
71 'style' => ['yatra-destination-shortcode'],
72 'script' => 'yatra-trip-category-shortcode',
73 ]
74 );
75
76 if ($block === false) {
77 $fallbackMeta = null;
78 $metaPath = BlockEditorScript::blockJsonPath('trip-category');
79 if (is_readable($metaPath)) {
80 $decoded = wp_json_file_decode($metaPath, ['associative' => true]);
81 $fallbackMeta = is_array($decoded) ? $decoded : null;
82 }
83
84 register_block_type('yatra/trip-category', [
85 'api_version' => 3,
86 'title' => __('Trip categories', 'yatra'),
87 'category' => 'yatra',
88 'description' => __('Display trip category cards with trip counts and pricing (same layout as destinations).', 'yatra'),
89 'icon' => 'category',
90 'keywords' => ['category', 'trip', 'taxonomy', 'yatra'],
91 'attributes' => is_array($fallbackMeta['attributes'] ?? null) ? $fallbackMeta['attributes'] : [],
92 'render_callback' => [$this, 'renderCallback'],
93 'editor_script' => 'yatra-trip-category-block-editor',
94 'editor_style' => ['yatra-listing', 'yatra-destination-shortcode'],
95 'style' => ['yatra-destination-shortcode'],
96 'script' => 'yatra-trip-category-shortcode',
97 'supports' => [
98 'align' => ['wide', 'full'],
99 'html' => false,
100 'inserter' => true,
101 ],
102 ]);
103 }
104 }
105 }
106