我在项目中使用自定义模块,它与Geolocation 1.11
模块配合良好。
在我将Geolocation
更新到3.7之后,我的自定义模块停止工作。
我发现,我的自定义模块使用了"GoogleMapsDisplayTrait.php"中的trait,现在它在Geolocation
中丢失了。就像
class LocationsMapBlock extends BlockBase {
use GoogleMapsDisplayTrait;
public function build() {
return [
'#theme' => 'locations_map',
'#attached' => [
'library' => ['location/map'],
'drupalSettings' => [
'geolocation' => [
'google_map_url' => $this->getGoogleMapsApiUrl(),
],
'locations' => $this->getLocationMapData(),
],
],
];
}
}
我发现现在与特征GoogleMapsDisplayTrait
(最相似的类在geolocation
模块的geolocation_google_maps
子模块内。
但现在它不是一个特性,而是一个抽象类,其方法与以前的特性相同。
abstract class GoogleMapsProviderBase extends MapProviderBase {
...
}
我试着添加这个类:
use Drupalgeolocation_google_mapsGoogleMapsProviderBase;
但现在我收到错误
'错误:调用Drupal\location\Plugin\Plock\LocationsMapBlock::getGoogleMapsApiUrl((中的未定义方法Drupal\location\Plugin\Block\LocationsMappingBlock->build(((modules/custom/location/src/Plugin/Block/LocationsMapBlock.php的第32行(
我的PHP知识是找到弱的解决方案。。。
未定义的函数getGoogleMapsApiUrl((是,也许文件丢失了?
检查文件是否存在:
/modules/geolocation/modules/geolocation_google_maps/src/GoogleMapsProviderBase.php
试着安装并启用以下模块,以便清洁工使用地理定位,特别是针对地理定位_google_maps:
geofield
geolocation_geofield
geolocation_google_maps
请尝试使用此调用,而不是$this->getGoogleMapsApiUrl((:
Drupal::service('plugin.manager.geolocation.mapprovider')->getMapProvider('google_maps')->getGoogleMapsApiUrl()