我正在尝试获取在 /admin/config/system/google-analytics 中设置的 Google Analytics ID (UA-xxxxxxx-yy)。是否可以将它作为控制器或表单中的变量,也许使用服务?
问问题
59 次
1 回答
0
从定义的模式中google_analytics.schema.yml
我们可以读到:
google_analytics.settings:
type: config_object
label: 'Google Analytics settings'
mapping:
account:
type: string
label: 'Web Property ID'
...
因此 Google Analytics ID 存储在 config 中,可以像这样检索:
$config = \Drupal::config('google_analytics.settings');
$id = $config->get('account');
于 2021-02-02T20:23:06.957 回答