


In the views.inc file, we have a simple $data array that we define our custom fields in. Go ahead and pop open both of these files so we can have a look: Let’s dig a bit deeper into one of these custom fields that we are using on the Govcon site. This is the only plugin that I have seen that requires this additional step! A Deeper Look at A Custom Field View plugins are a little strange, and I do want to acknowledge that for this example there is one additional step that you “usually” don’t have to do.Ĭustom Views fields require you to implement hook_views_data_alter in a. You will likely do it fairly frequently if you are writing custom PHP for Drupal 8/9+.
#Drupal wiki plugin how to
Regardless, learning how to write a custom plugin is an invaluable part of your D9 module development toolbox.

Ever.Īside from that, the Plugin system provides a convenient method of adding your own “custom stuff” to Drupal! Some common examples (aside from views fields) are Block Plugins (different than Custom Block Content), Field Widgets / Formatters, Migrations, etc. If you accidentally make Views or Field capital, or make field plural, it will not work. But in this case, for a views field, the Plugin Class absolutely most live at src / Plugin / views / field. Each plugin has its own specific requirements. The directory structure here is critical. The capitalcamp_glue module has 5 custom views fields in it. This post is all about creating a custom views field for D9 using the Plugin System. Why would you want to do this? Usually it’s because there isn’t a stock views field for something you want to do or if there is a field, it doesn’t do it quite in the way that you wanted to handle it. In fact, the code sample I submitted to Acquia nearly 4 years ago when I applied for my role as an architect was a D7 example of this! ( here’s a link if you’re curious, I make no promises about it working, it’s been 4 years since I even looked at it). I’ve been writing custom views fields for years. If you haven’t read my introduction to Drupal 9 module development, I would suggest you start there! I want this blog to be the most accurate representation of Drupal today that I can (and it certainly takes a community).
#Drupal wiki plugin update
I will research their feedback and post an update once I have a working example. But as per the comments of Shelane and Gábor below, there may be better / more precise ways to accomplish this. A note and update (November 13, 2020): I’ve received some feedback that portions of this post are out of date! That’s not good! I will say, this tutorial still works.
