How to process a View custom field

Created on 3 July 2024, 5 months ago

Problem/Motivation

I can't read the value of a custom field added to the View

Steps to reproduce

Create a @ViewsField in a custom module. In my case is a simple checkbox like with the following code

public function render(ResultRow $values) {
  return [
    '#type' => 'checkbox',
    '#title' => $this->t('Select'),
    '#default_value' => FALSE,
    '#attributes' => [
      'id' => 'custom_checkbox_' . $values->_entity->id(),
      'name' => 'custom_checkbox[]',
      'value' => $values->_entity->id(),
      'class' => ['custom-checkbox-class'],
    ],
  ];
}

Then try to read the submitted value from a custom ViewsBulkOperationsActionBase action.
I've tried the following method

// Debug of the view
$view = $this->view;
\Drupal::logger('tester')->debug("getExposedInput <pre>".print_r($view->getExposedInput(), 1)."</pre>");
\Drupal::logger('tester')->debug("getResponse <pre>".print_r($view->getResponse(), 1)."</pre>");
\Drupal::logger('tester')->debug("getRequest <pre>".print_r($view->getRequest(), 1)."</pre>");
\Drupal::logger('tester')->debug("view <pre>".print_r($view->result, 1)."</pre>");

// Debug of the entity
\Drupal::logger('tester')->debug("entity <pre>".print_r($entity, 1)."</pre>");

// Debug of the context
$cont = $this->context;
\Drupal::logger('tester')->debug("context <pre>".print_r($cont, 1)."</pre>");

No one work.

Can someone help me?
Thanks

💬 Support request
Status

Active

Version

4.3

Component

Integration

Created by

🇮🇹Italy g.rocchini

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

Comments & Activities

Production build 0.71.5 2024