VBO Action for contrib Profile entity with Workflow

Created on 29 July 2020, over 4 years ago
Updated 8 March 2024, 10 months ago

Problem/Motivation

This is with the Workflow Field approach. So I have users who fill out a profile, but not the one that is part of core for adding fields directly to the user form. I needed a separate profile type for a set of users who are "affiliated" and login to the site with SSO / SAML. So I'm making use of Profile v8.x-1.1 ( https://www.drupal.org/project/profile β†’ ) and have created one profile type that is associated with each user.

Using Workflow Field, I have a "status" field that allows administrators to moderate users by choosing between two states - "inactive" or "confirmed". If they are set as "confirmed" then they show up on a list on a separate part of the site.

This works great, but what I really want to do here is create a dashboard of sorts that allows admins to get a list of all of the users and be able to select one or more of them and transition them from one state to another as needed. I setup VBO for this in a view, but there are no "transition A <-> B" options in VBO. I believe this is because the view is using the User entity type with a relationship to Profile, and Workflow only seems to work specifically on Node types.

Steps to reproduce

Drupal 8.9.2
Workflow 8.x-1.4
Profile 8.x-1.1

- Install profile module and create a new profile type. Add a new field of type "Workflow State" (after adding any number of arbitrary states and transitions). Under Manage Form Display for this field I ran into issues with the default widget "Workflow transition form" so I changed this to "Select list".

- I added a hook in a custom module via hook_entity_field_access() to hide the field from certain roles

- Create a view with type Users, not Content, and add a relationship to Profile. This is so I can display other fields on the profile such as name, email, etc.

- Add a Views Bulk Operation field and look at the available actions - no workflow actions are available.

Proposed resolution

It's right in the workflow method names like "workflow_node_current_state()", but is it possible to have an action that works on other entity types?

I admit I'm ignorant about most of the inner workings of Workflow, so maybe I'm missing something? I tried creating a custom Action plugin, which appears in the VBO action list but doesn't end up actually doing anything. I extended WorkflowStateActionBase and made a quick attempt with the execute method:

/**
 * @Action(
 *   id = "account_status_transition",
 *   label = @Translation("Account Status Transition"),
 *   type = "",
 *   confirm = TRUE
 * )
 */
class AccountStatusAction extends WorkflowStateActionBase {

 ... various 

public function execute($entity = NULL) {
    if ($entity instanceof User) {
      $uid = $entity->id();
      $profile = Profile::load($uid); //@Drupal\profile\Entity\Profile
      
      if (!$transition = $this->getTransitionForExecution($profile)) {
        $this->messenger()->addStatus('The entity is not valid for this action.');
        return;
      }
      workflow_execute_transition($transition, FALSE);
    }

    return $this->t('??');
  }

I choose the Account Status Transition action in the view after selecting a user which brings up:

Selected 1 entities:
testuser

.. and the workflow transition form. I change the account status field from inactive to confirmed and save successfully, but when I'm done there are no changes. No errors or warnings either. Maybe this is a VBO thing as well?

Any questions or advice is very welcome, thanks.

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.0

Component

Views VBO

Created by

πŸ‡ΊπŸ‡ΈUnited States JeffC518

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024