PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
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 trunk, at app/Blocks/DestinationBlock.php

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