Skip to content

Commit

Permalink
Merge pull request #172 from Chi-teck/php-attribute-views-style
Browse files Browse the repository at this point in the history
Use PHP attribute for ViewsStyle plugin.
  • Loading branch information
Chi-teck committed May 24, 2024
2 parents 32beb00 + 9595f07 commit 730fa2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
23 changes: 13 additions & 10 deletions templates/Plugin/Views/_style/style.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ declare(strict_types=1);

namespace Drupal\{{ machine_name }}\Plugin\views\style;

{% if configurable %}
{% apply sort_namespaces %}
{% if configurable %}
use Drupal\Core\Form\FormStateInterface;
{% endif %}
{% endif %}
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
{% endapply %}

/**
* {{ plugin_label }} style plugin.
*
* @ViewsStyle(
* id = "{{ plugin_id }}",
* title = @Translation("{{ plugin_label }}"),
* help = @Translation("@todo Add help text here."),
* theme = "views_style_{{ plugin_id }}",
* display_types = {"normal"},
* )
*/
#[ViewsStyle(
id: '{{ plugin_id }}',
title: new TranslatableMarkup('{{ plugin_label }}'),
help: new TranslatableMarkup('@todo Add help text here.'),
theme: 'views_style_{{ plugin_id }}',
display_types: ['normal'],
)]
final class {{ class }} extends StylePluginBase {

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

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsStyle;
use Drupal\views\Plugin\views\style\StylePluginBase;

/**
* Foo style plugin.
*
* @ViewsStyle(
* id = "example_foo",
* title = @Translation("Foo"),
* help = @Translation("@todo Add help text here."),
* theme = "views_style_example_foo",
* display_types = {"normal"},
* )
*/
#[ViewsStyle(
id: 'example_foo',
title: new TranslatableMarkup('Foo'),
help: new TranslatableMarkup('@todo Add help text here.'),
theme: 'views_style_example_foo',
display_types: ['normal'],
)]
final class Foo extends StylePluginBase {

/**
Expand Down

0 comments on commit 730fa2c

Please sign in to comment.