PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.6
Yatra – Travel Booking & Tour Operator Software v3.0.2.6
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.2.6, at app/Blocks/TourBlock.php

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