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 / DestinationBlock.php

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

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