I want to create a views field plugin. At the moment, I just want to display "Hello world".
I have a custom module "lazy_admin".
This is lazy_admin.info.yml
name: 'lazy_admin'
type: module
description: 'Misc code'
package: Custom
core_version_requirement: ^10
dependencies:
- drupal:views
This is my views plugin class OpenTickets.php (web/modules/custom/lazy_admin/src/Plugin/views/field/OpenTickets.php)
<?php
namespace Drupal\lazy_admin\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* @ViewsField("open_tickets")
*/
class OpenTickets extends FieldPluginBase {
/**
* Defines how the field is displayed.
*
* @param ResultRow $values
*
* @return mixed|string
*/
public function render(ResultRow $values) {
return $this->t('Hello world');
}
}
When I enable the module and clear the cache, I expect to be able to select the plugin in the views UI here (I'm using gin admin theme):
But I cannot find the new field anywhere.
I'm probably missing something obvious, or fundamentally misunderstanding something.
I'm using Drupal 10.2 & PHP 8.2.