地理定位模块-如何正确调用抽象类方法
我在项目中使用自定义模块,它与 Geolocation 1.11
模块配合得很好。
将 Geolocation
更新到 3.7 后,我的自定义模块停止工作。
我发现 - 我的自定义模块正在使用“GoogleMapsDisplayTrait.php”中的特征,但现在它在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 Drupal\geolocation_google_maps\GoogleMapsProviderBase;
但现在我收到错误
“错误:调用 Drupal\location\Plugin\Block\LocationsMapBlock::getGoogleMapsApiUrl() in Drupal\location\Plugin\Block\LocationsMapBlock-> 中的未定义方法” ;build()(modules/custom/location/src/Plugin/Block/LocationsMapBlock.php 第 32 行)。
我的 PHP 知识太薄弱,无法找到解决方案......
I'm using the custom module in my project, and it was working fine with Geolocation 1.11
module.
After I've updated Geolocation
to 3.7 my custom module stopped working.
What I've found - my custom module was using trait from 'GoogleMapsDisplayTrait.php' and now it is missing in Geolocation
. It was like that
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(),
],
],
];
}
}
I've found that now most similar class to trait GoogleMapsDisplayTrait
) is inside geolocation_google_maps
submodule of geolocation
module.
But now it's not a trait, but abstract class with the same methods as previous trait was.
abstract class GoogleMapsProviderBase extends MapProviderBase {
...
}
I've tried to add this class:
use Drupal\geolocation_google_maps\GoogleMapsProviderBase;
But now I'm receiving the error
'Error: Call to undefined method Drupal\location\Plugin\Block\LocationsMapBlock::getGoogleMapsApiUrl() in Drupal\location\Plugin\Block\LocationsMapBlock->build() (line 32 of modules/custom/location/src/Plugin/Block/LocationsMapBlock.php).'
My PHP knowledges is to weak to find the solution...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
未定义的函数getGoogleMapsApiUrl()是,也许文件丢失了?
检查文件是否存在:
尝试安装并启用以下模块,以便清理器使用地理定位 - 特别是 geolocation_google_maps:
尝试使用此模块调用而不是 $this->getGoogleMapsApiUrl():
The undefined function getGoogleMapsApiUrl() is, maybe the file is missing?
Check if the file exists:
Try to install and enable the following modules for a cleaner working with geolocation - specially for the geolocation_google_maps:
Try using this call instead of $this->getGoogleMapsApiUrl():