在Drupal 8中动态更改注释值

时间:2017-12-25 18:47:34

标签: drupal-8

如何在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

1 个答案:

答案 0 :(得分:2)

使用hook_queue_info_alter

function mymodule_queue_info_alter(&$queues) {
  $queues['google_analytics_counter_worker']['cron']['time'] = DURATION;
}