Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ymap.php
1<?php
2
4
10use Bitrix\Main\Page\Asset;
12
13Loc::loadMessages(__FILE__);
14
15class YMap extends Page
16{
21 protected function getMap()
22 {
23 $helpUrl = Help::getHelpUrl('GMAP_EDIT');
24 return [
25 'USE' => new Field\Checkbox('USE', [
26 'title' => Loc::getMessage('LANDING_HOOK_YMAPCODE_USE'),
27 ]),
28 'CODE' => new Field\Text('CODE', [
29 'title' => Loc::getMessage('LANDING_HOOK_YMAPCODE'),
30 'placeholder' => Loc::getMessage('LANDING_HOOK_YMAPCODE_PLACEHOLDER'),
31 'help' => $helpUrl
32 ? '<a href="' . $helpUrl . '" target="_blank">'
33 . Loc::getMessage('LANDING_HOOK_YMAPCODE_HELP')
34 . '</a>'
35 : '',
36 ]),
37 ];
38 }
39
44 public function enabled()
45 {
46 if ($this->issetCustomExec())
47 {
48 return true;
49 }
50
51 if ($this->isPage())
52 {
53 return false;
54 }
55
56 return
57 $this->fields['USE']->getValue() === 'Y'
58 && !empty($this->fields['CODE']->getValue());
59 }
60
65 public function exec()
66 {
67 if ($this->execCustom())
68 {
69 return;
70 }
71
73 {
74 return;
75 }
76
77 $code = HtmlFilter::encode(trim($this->fields['CODE']));
78 $assets = Asset::getInstance();
79
80 $assets->addString(
81 "<script defer>
82 (function(){
83 'use strict';
84 //fake function, if API will loaded fasten than blocks
85 window.onYandexMapApiLoaded = function(){}
86 })();
87 </script>"
88 );
89
90 // todo: lang=language_region https://yandex.ru/dev/maps/jsapi/doc/2.1/dg/concepts/localization.html
91 // todo: load = modules https://yandex.ru/dev/maps/jsapi/doc/2.1/dg/concepts/modules.html
92 $assets->addString(
93 '<script src="https://api-maps.yandex.ru/2.1/?apikey='
94 . $code
95 . '&lang=ru_RU&onload=onYandexMapApiLoaded" type="text/javascript"></script>'
96 );
97 }
98}
static getHelpUrl(string $code)
Definition help.php:268
static availableOnlyForZone(string $zone)
Definition manager.php:975
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29