【问题标题】:Dynamically change annotation value in Drupal 8在 Drupal 8 中动态更改注释值
【发布时间】:2017-12-25 18:47:34
【问题描述】:

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

【问题讨论】:

    标签: drupal-8


    【解决方案1】:

    为此使用hook_queue_info_alter

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

    【讨论】:

    • 完美。谢谢。
    猜你喜欢
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多