如何在Drupal 8中动态更改注释值?例如,我希望以下注释中的cron = {"time" = 120}
为cron = {"time" = 600}
。我想从配置中获得600或其他一些值。
/**
* Updates the google analytics counters.
*
* @QueueWorker(
* id = "google_analytics_counter_worker",
* title = @Translation("Import Data from Google Analytics"),
* cron = {"time" = 120}
* )
*/
我尝试在注释之前添加常量:
const DURATION = 600;
/**
* Updates the google analytics counters.
*
* @QueueWorker(
* id = "google_analytics_counter_worker",
* title = @Translation("Import Data from Google Analytics"),
* cron = {"time" = DURATION}
* )
*/
但它引发了一个错误:
Doctrine\Common\Annotations\AnnotationException: [Semantical Error] Couldn't find constant DURATION, class [error]
Drupal\google_analytics_counter\Plugin\QueueWorker\GoogleAnalyticsCounterQueue. in
/private/var/www/sites/mskcc_deploy/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
答案 0 :(得分:2)
function mymodule_queue_info_alter(&$queues) {
$queues['google_analytics_counter_worker']['cron']['time'] = DURATION;
}