PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.10
Yatra – Travel Booking & Tour Operator Software v3.0.10
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 / Blocks / TourBlock.php

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

105 lines 3.3 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 * Tour Block
12 *
13 * Gutenberg block for displaying tour/trip packages
14 * Maintains backward compatibility with old yatra/tour block
15 *
16 * @package Yatra\Blocks
17 * @since 3.0.0
18 */
19 class TourBlock
20 {
21 public function __construct()
22 {
23 $this->register();
24 }
25
26 /**
27 * @param array<string, mixed> $attributes Block attributes
28 * @param string $content Block content
29 */
30 public function renderCallback(array $attributes, string $content): string
31 {
32 FrontendAssetsProvider::registerCoreFrontendStylesheets();
33 wp_enqueue_style('yatra-trip-shortcode');
34
35 return BlockDataService::renderTripBlock($attributes);
36 }
37
38 public function register(): void
39 {
40 BlockEditorScript::reclaimBlockName('yatra/tour');
41
42 $editorDeps = BlockEditorScript::editorDependencies();
43 if (! BlockEditorScript::register('yatra-tour-block-editor', 'tour', $editorDeps)) {
44 return;
45 }
46
47 FrontendAssetsProvider::registerCoreFrontendStylesheets();
48
49 wp_register_style(
50 'yatra-listing',
51 \YATRA_PLUGIN_URL . 'assets/css/listing.css',
52 [],
53 YATRA_VERSION
54 );
55
56 $tripShortcodeCss = \YATRA_PLUGIN_PATH . 'assets/css/shortcodes/trip-shortcode.css';
57 $tripShortcodeVer = is_readable($tripShortcodeCss) ? YATRA_VERSION . '.' . filemtime($tripShortcodeCss) : YATRA_VERSION;
58 wp_register_style(
59 'yatra-trip-shortcode',
60 \YATRA_PLUGIN_URL . 'assets/css/shortcodes/trip-shortcode.css',
61 FrontendAssetsProvider::shortcodeStyleDependencies(),
62 $tripShortcodeVer
63 );
64
65 wp_register_script(
66 'yatra-trip-shortcode',
67 \YATRA_PLUGIN_URL . 'assets/js/trip-shortcode.js',
68 ['jquery'],
69 YATRA_VERSION,
70 true
71 );
72
73 $block = register_block_type_from_metadata(
74 BlockEditorScript::blockJsonPath('tour'),
75 [
76 'render_callback' => [$this, 'renderCallback'],
77 'editor_style' => ['yatra-listing', 'yatra-trip-shortcode'],
78 'style' => ['yatra-trip-shortcode'],
79 'script' => 'yatra-trip-shortcode',
80 ]
81 );
82
83 if ($block === false) {
84 register_block_type('yatra/tour', [
85 'api_version' => 3,
86 'title' => __('Trip', 'yatra'),
87 'category' => 'yatra',
88 'description' => __('Display trip listings with customizable options', 'yatra'),
89 'icon' => 'palmtree',
90 'keywords' => ['tour', 'trip', 'travel', 'yatra'],
91 'render_callback' => [$this, 'renderCallback'],
92 'editor_script' => 'yatra-tour-block-editor',
93 'editor_style' => ['yatra-listing', 'yatra-trip-shortcode'],
94 'style' => ['yatra-trip-shortcode'],
95 'script' => 'yatra-trip-shortcode',
96 'supports' => [
97 'align' => ['wide', 'full'],
98 'html' => false,
99 'inserter' => true,
100 ],
101 ]);
102 }
103 }
104 }
105