Skip to content

Commit

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

{% apply sort_namespaces %}
use Drupal\Core\Condition\Attribute\Condition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
{% if services %}
Expand All @@ -17,12 +19,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides a '{{ plugin_label }}' condition.
*
* @Condition(
* id = "{{ plugin_id }}",
* label = @Translation("{{ plugin_label }}"),
* )
*/
#[Condition(
id: '{{ plugin_id }}',
label: new TranslatableMarkup('{{ plugin_label }}'),
)]
final class {{ class }} extends ConditionPluginBase {% 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\foo\Plugin\Condition;

use Drupal\Core\Condition\Attribute\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Provides a 'Example' condition.
*
* @Condition(
* id = "foo_example",
* label = @Translation("Example"),
* )
*/
#[Condition(
id: 'foo_example',
label: new TranslatableMarkup('Example'),
)]
final class Example extends ConditionPluginBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

namespace Drupal\foo\Plugin\Condition;

use Drupal\Core\Condition\Attribute\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\CronInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides a 'Example' condition.
*
* @Condition(
* id = "foo_example",
* label = @Translation("Example"),
* )
*/
#[Condition(
id: 'foo_example',
label: new TranslatableMarkup('Example'),
)]
final class Example extends ConditionPluginBase implements ContainerFactoryPluginInterface {

/**
Expand Down

0 comments on commit 0395af0

Please sign in to comment.