In my drupal commerce, I'd like to add a textarea where the user can make some comment on his order (which will be added to the commerce order comment workflow)

So I've generate with drush my field


namespace Drupal\my_module\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

 * Provides CommentaireClient field handler.
 * @ViewsField("commerce_order_commentaire_client")
 * @DCG
 * The plugin needs to be assigned to a specific table column through
 * hook_views_data() or hook_views_data_alter().
 * For non-existent columns (i.e. computed fields) you need to override
 * self::query() method.
class CommerceOrderCommentaireClient extends FieldPluginBase {

   * {@inheritdoc}
  public function render(ResultRow $values) {
    $value = parent::render($values);
    // @DCG Modify or replace the rendered value here.
    return $value;


and then I've added it to the view


 * Implements hook_views_data_alter().
function mymodule_views_data_alter(array &$data) {
  $data['commerce_order']['commentaire_client'] = [
    'title' => t('Commentaire client'),
    'help' => t('Zone de texte que le client peut saisir'),
    'field' => [
      'id' => 'commerce_order_commentaire_client',

This part is working, i've my row inside my global view variables.

enter image description here

but when I try to add it, I have this error (translated) :

The handler for this element is faulty or missing. The following details are available:

Activating the appropriate module may solve this problem. If not, check if there is a module update available.

and I have those error in my watchdog :

Warning : Invalid argument supplied for foreach() dans template_preprocess_item_list() (/var/www/html/web/core/includes/theme.inc ligne 1147)

#0 /var/www/html/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Invalid argumen...', '/var/www/html/w...', 1147)
#1 /var/www/html/web/core/includes/theme.inc(1147): _drupal_error_handler(2, 'Invalid argumen...', '/var/www/html/w...', 1147, Array)
#2 [internal function]: template_preprocess_item_list(Array, 'item_list', Array)

what did I missed ? I'm using drupal commerce 2.24 and drupal 9.4


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.