1 <?php
2 3 4 5 6 7 8
9 class YandexMapsWidget extends SidebarWidget {
10
11 static $db = array(
12 'Longitude' => 'Decimal(10,4)',
13 'Latitude' => 'Decimal(10,4)',
14 'Link' => 'Varchar(255)',
15 'OpenInNewWindow' => 'Boolean',
16 );
17
18 function getCMSFields() {
19 $fields = parent::getCMSFields();
20
21 $sc = SiteConfig::current_site_config();
22 $fields->addFieldToTab('Root.Main', new HeaderField('YandexMapHeader', _t('YandexMapsHomepageWidget.MapHeader', 'Карта яндекса')), 'Longitude');
23 if (!$sc->isNeedMapApiKey()) {
24 $fields->addFieldToTab('Root.Main', new LiteralField('NoMapApiKey', _t("SiteConfig.NoMapApiKeyMessage")), 'Longitude');
25 $fields->removeByName('Longitude');
26 $fields->removeByName('Latitude');
27 $fields->removeByName('Link');
28 $fields->removeByName('OpenInNewWindow');
29 }
30 else {
31 $fields->addFieldToTab('Root.Main', new LiteralField('YandexMap', sprintf('<a href="#" class="popuplink" id="map_object_ymap_link">%s</a>', _t('YandexMapsHomepageWidget.MapLink', 'Указать объект на Яндекс.Карте'))), 'Longitude');
32 $fields->addFieldToTab('Root.Main', new LiteralField('MapPageType', '<div state="not_loaded" id="map_object_ymap"></div>'));
33
34
35 $sc->RequireMapApi('https://api-maps.yandex.ru/2.0.48/?load=package.full&lang=ru-RU&apikey=');
36 Requirements::css('widgets/css/map_objects_map.css');
37 Requirements::javascript('widgets/javascript/map_objects.js');
38 }
39
40 return $fields;
41 }
42
43 function canCreate($area = null) {
44 $rs = parent::canCreate($area);
45 if (!SiteConfig::current_site_config()->isNeedMapApiKey()) {
46 $rs = false;
47 }
48 return $rs;
49 }
50
51 function hasContent() {
52 if ($this->Longitude && $this->Latitude) {
53 return true;
54 }
55 return false;
56 }
57 }
58
59
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-