<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=278116885016877&amp;ev=PageView&amp;noscript=1">

, , , ,

May 22, 2019 | 1 Minute Read

Creating A Custom View Field In Drupal 8 To Use With Workflow States

Table of Contents


When it comes to the workflow module, adding the view field is simple, but again there may be scenarios where you have to add custom functionality in the query or options. Even otherwise, this article helps with creating a simple view field in Drupal 8. In this example, we will consider a workflow state as a phase of the node.

To create a new view field, you have to first define it in the custom_module_views_data(). Insert the following piece of code in your custom_module.module file:


After that is done, clear cache and search for the field in the view. You will see the label ‘Phase’, although selecting it won’t do anything because we haven’t defined it yet. That is the next step. In the custom module, create a file ‘PhaseViewsField.php’ in the folder Plugin/views/field with the following code:


Now you can clear cache again and add the field in the view. You can also use this field to add a custom filter.

About the Author
Abhai Sasidharan, Axelerant Alumni
About the Author

Abhai Sasidharan, Axelerant Alumni

Back to Top