Skip to content

Commit b81e31c

Browse files
authored
Merge pull request #168 from Chi-teck/php-attribute-views-field
Use PHP attribute for ViewsField plugin
2 parents a4b5581 + 0f24bc0 commit b81e31c

File tree

3 files changed

+6
-6
lines changed
  • templates/Plugin/Views/_field
  • tests/functional/Generator/Plugin/Views/_field

3 files changed

+6
-6
lines changed

templates/Plugin/Views/_field/field.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Drupal\{{ machine_name }}\Plugin\views\field;
77
88
{% apply sort_namespaces %}
99
use Drupal\Component\Render\MarkupInterface;
10+
use Drupal\views\Attribute\ViewsField;
1011
use Drupal\views\Plugin\views\field\FieldPluginBase;
1112
use Drupal\views\ResultRow;
1213
{% if configurable %}
@@ -21,8 +22,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
2122
/**
2223
* Provides {{ plugin_label }} field handler.
2324
*
24-
* @ViewsField("{{ plugin_id }}")
25-
*
2625
* @DCG
2726
* The plugin needs to be assigned to a specific table column through
2827
* hook_views_data() or hook_views_data_alter().
@@ -37,6 +36,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
3736
* }
3837
* @endcode
3938
*/
39+
#[ViewsField('{{ plugin_id }}')]
4040
final class {{ class }} extends FieldPluginBase {
4141
4242
{% if services %}

tests/functional/Generator/Plugin/Views/_field/_n_deps/_n_config/src/Plugin/views/field/Example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
namespace Drupal\foo\Plugin\views\field;
66

77
use Drupal\Component\Render\MarkupInterface;
8+
use Drupal\views\Attribute\ViewsField;
89
use Drupal\views\Plugin\views\field\FieldPluginBase;
910
use Drupal\views\ResultRow;
1011

1112
/**
1213
* Provides Example field handler.
1314
*
14-
* @ViewsField("foo_example")
15-
*
1615
* @DCG
1716
* The plugin needs to be assigned to a specific table column through
1817
* hook_views_data() or hook_views_data_alter().
@@ -27,6 +26,7 @@
2726
* }
2827
* @endcode
2928
*/
29+
#[ViewsField('foo_example')]
3030
final class Example extends FieldPluginBase {
3131

3232
/**

tests/functional/Generator/Plugin/Views/_field/_w_deps/_w_config/src/Plugin/views/field/Example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
use Drupal\Component\Render\MarkupInterface;
88
use Drupal\Core\Entity\EntityTypeManagerInterface;
99
use Drupal\Core\Form\FormStateInterface;
10+
use Drupal\views\Attribute\ViewsField;
1011
use Drupal\views\Plugin\views\field\FieldPluginBase;
1112
use Drupal\views\ResultRow;
1213
use Symfony\Component\DependencyInjection\ContainerInterface;
1314

1415
/**
1516
* Provides Example field handler.
1617
*
17-
* @ViewsField("foo_example")
18-
*
1918
* @DCG
2019
* The plugin needs to be assigned to a specific table column through
2120
* hook_views_data() or hook_views_data_alter().
@@ -30,6 +29,7 @@
3029
* }
3130
* @endcode
3231
*/
32+
#[ViewsField('foo_example')]
3333
final class Example extends FieldPluginBase {
3434

3535
/**

0 commit comments

Comments
 (0)