1

I'm on Drupal 10.2.x and editing the view content. I'm using the contrib module views_cm_current_state.

The module implements hook_views_data() to add, for what I understand, a new field. The field itself is a plugin of @ViewsField, which print the "label" of the moderation state:

$current_state = $this->moderationInformation->getWorkflowForEntity($entity)->getTypePlugin()->getState($entity->moderation_state->value)->label();

I am currently using the field to print the result, which is fine.

However, I also need to use it in a conditional logic to rewrite another field on the views. Therefore I'd need to access to the machine name rather than the label of the moderation_state.

I can obliviously duplicate the code for another field, but I know that in the rewrite section is possible to access the raw value as replacement for many fields, e.g. for the title {{ title__value }}.

The question is: is possible to add "the raw value" to the kind of field provided by the module?

I have very basic knowledge of Views by the programmatic point of view, so both "theorical" explanation, or point to where find it, or suggestions to solve this issue would be appreciated, thanks.

1
  • The Views field plugin needs to implement addSelfTokens(), see for example Roles::addSelfTokens. Most fields in Drupal are entity fields and the Views entity field base class already implements this method to get raw values.
    – 4uk4
    Commented May 20 at 7:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.