Skip to content
Field note

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

Introduction

May 22, 2019·1 min read·Abhai Sasidharan, Axelerant Alumni/ Field correspondent
Creating A Custom View Field In Drupal 8 To Use With Workflow States

Introduction

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.

Companion brief

Bring this dispatch into a working session - one page in, scoping memo out.

Brief Foyer
Pressure-test "Field note" with a partner

If this dispatch landed, bring it into a room with us.

The argument in "Creating A Custom View Field In Drupal 8 To Use With Workflow States" is ours - but every situation breaks the argument differently. Send the situation in one page and a named partner will reply inside one business day with a scoping memo: where the argument holds for you, where it bends, and what we'd actually do in the first two weeks.

One-pager · Field note

By submitting this form you acknowledge that you have read Axelerant's Privacy Policy and agree to its terms.

Replied to by a named partner within one business day.