Skip to content

Commit

Permalink
Merge pull request #161 from Chi-teck/php-attribute-queue-worker
Browse files Browse the repository at this point in the history
Use PHP attribute for QueueWorker plugin.
  • Loading branch information
Chi-teck committed May 21, 2024
2 parents 7541424 + c68e0b8 commit f412326
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
13 changes: 7 additions & 6 deletions templates/Plugin/_queue-worker/queue-worker.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ declare(strict_types=1);
namespace Drupal\{{ machine_name }}\Plugin\QueueWorker;

{% apply sort_namespaces %}
use Drupal\Core\Queue\Attribute\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
{% if services %}
{{ di.use(services) }}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Expand All @@ -16,13 +18,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines '{{ plugin_id }}' queue worker.
*
* @QueueWorker(
* id = "{{ plugin_id }}",
* title = @Translation("{{ plugin_label }}"),
* cron = {"time" = 60},
* )
*/
#[QueueWorker(
id: '{{ plugin_id }}',
title: new TranslatableMarkup('{{ plugin_label }}'),
cron: ['time' => 60],
)]
final class {{ class }} extends QueueWorkerBase {% if services %}implements ContainerFactoryPluginInterface {% endif %}{

{% if services %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Drupal\example\Plugin\QueueWorker;

use Drupal\Core\Queue\Attribute\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Defines 'example_foo_bar' queue worker.
*
* @QueueWorker(
* id = "example_foo_bar",
* title = @Translation("Test"),
* cron = {"time" = 60},
* )
*/
#[QueueWorker(
id: 'example_foo_bar',
title: new TranslatableMarkup('Test'),
cron: ['time' => 60],
)]
final class FooBar extends QueueWorkerBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
namespace Drupal\example\Plugin\QueueWorker;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\Attribute\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines 'example_foo_bar' queue worker.
*
* @QueueWorker(
* id = "example_foo_bar",
* title = @Translation("Test"),
* cron = {"time" = 60},
* )
*/
#[QueueWorker(
id: 'example_foo_bar',
title: new TranslatableMarkup('Test'),
cron: ['time' => 60],
)]
final class FooBar extends QueueWorkerBase implements ContainerFactoryPluginInterface {

/**
Expand Down

0 comments on commit f412326

Please sign in to comment.