PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.11
Yatra – Travel Booking & Tour Operator Software v3.0.11
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 / ActivityBlock.php

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

105 lines 3.4 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 * Activity Block
12 *
13 * Gutenberg block for displaying activity listings
14 * Maintains backward compatibility with old yatra/activity block
15 *
16 * @package Yatra\Blocks
17 * @since 3.0.0
18 */
19 class ActivityBlock
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-activity-shortcode');
34
35 return BlockDataService::renderActivityBlock($attributes);
36 }
37
38 public function register(): void
39 {
40 BlockEditorScript::reclaimBlockName('yatra/activity');
41
42 $editorDeps = BlockEditorScript::editorDependencies();
43 if (! BlockEditorScript::register('yatra-activity-block-editor', 'activity', $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 $activityShortcodeCss = \YATRA_PLUGIN_PATH . 'assets/css/shortcodes/activity-shortcode.css';
57 $activityShortcodeVer = is_readable($activityShortcodeCss) ? YATRA_VERSION . '.' . filemtime($activityShortcodeCss) : YATRA_VERSION;
58 wp_register_style(
59 'yatra-activity-shortcode',
60 \YATRA_PLUGIN_URL . 'assets/css/shortcodes/activity-shortcode.css',
61 FrontendAssetsProvider::shortcodeStyleDependencies(),
62 $activityShortcodeVer
63 );
64
65 wp_register_script(
66 'yatra-activity-shortcode',
67 \YATRA_PLUGIN_URL . 'assets/js/activity-shortcode.js',
68 ['jquery'],
69 YATRA_VERSION,
70 true
71 );
72
73 $block = register_block_type_from_metadata(
74 BlockEditorScript::blockJsonPath('activity'),
75 [
76 'render_callback' => [$this, 'renderCallback'],
77 'editor_style' => ['yatra-listing', 'yatra-activity-shortcode'],
78 'style' => ['yatra-activity-shortcode'],
79 'script' => 'yatra-activity-shortcode',
80 ]
81 );
82
83 if ($block === false) {
84 register_block_type('yatra/activity', [
85 'api_version' => 3,
86 'title' => __('Activity', 'yatra'),
87 'category' => 'yatra',
88 'description' => __('Display activity listings with customizable options', 'yatra'),
89 'icon' => 'buddicons-pm',
90 'keywords' => ['activity', 'things to do', 'yatra'],
91 'render_callback' => [$this, 'renderCallback'],
92 'editor_script' => 'yatra-activity-block-editor',
93 'editor_style' => ['yatra-listing', 'yatra-activity-shortcode'],
94 'style' => ['yatra-activity-shortcode'],
95 'script' => 'yatra-activity-shortcode',
96 'supports' => [
97 'align' => ['wide', 'full'],
98 'html' => false,
99 'inserter' => true,
100 ],
101 ]);
102 }
103 }
104 }
105