How make a virtual field for view? i want a vitual field for print value of sum in another entity :

My 2 custom entity content :


  commandes_entity
  
  commandesLignes_entity reference to commandes_entity


In the commandes_entity i have a view table who liste all my lines.
i want to add a custom column who sum all the children in commandesLignes_entity.

For that i make a field in .module : 

function hook_views_data()
{

  $data['commandes_entity'] = array(

      'totalCommandeTTC' =&gt; array(
          'title' =&gt; t('Total Commande TTC'),
          'help' =&gt; t("Le total des commandes"),
          'field' =&gt; array(
              'id' =&gt; 'machine_name',
              'options callback' =&gt; 'Drupal\boutique\Controller\TestController::content',

          ),

          'sort' =&gt; array(
              'id' =&gt; 'standard',
          ),

      ),

  );

return $data;
}


This field is in my select field view, when i add it all is ok except one thing :


  SQLSTATE[42S22]: Column not found: 1054 Unknown column
  'commandes_entity.totalCommandeTTC' in 'field list': SELECT
  commandes_entity.totalCommandeTTC AS
  commandes_entity_totalcommandettc, commandes_entity.id AS id FROM
  {commandes_entity} commandes_entity WHERE (( (commandes_entity.statut
  LIKE :db_condition_placeholder_0 ESCAPE '\') )) ORDER BY
  commandes_entity.created DESC LIMIT 21 OFFSET 0; Array (
  [:db_condition_placeholder_0] => payer )


This field 


  totalCommandeTTC


doesn't exist in my table, i want it virtual.

For now my callback just return 'test'.

Any idea for make this field really virtual ?

I try to move it to views group like this : 

function boutique_views_data()
{

  $data['views'] = array(

      'totalCommandeTTC' =&gt; array(
          'title' =&gt; t('Total Commande TTC'),
          'help' =&gt; t("Le total des commandes"),
          'field' =&gt; array(
              'id' =&gt; 'machine_name',
              'options callback' =&gt; 'Drupal\boutique\Controller\TestController::content',

          ),

          'sort' =&gt; array(
              'id' =&gt; 'standard',
          ),

      ),

  );

return $data;
}


The field is in the Global group but SQL still try to get it into the commandes_entity table.
Thank to Clive for guide me :

This is how i make a virtual field :

First you need to create the handler for the field :

&lt;?php

namespace Drupal\boutique\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;

/**
 * Field handler to present the path to the node.
 *
 * @ingroup views_field_handlers
 *
 * @ViewsField("totalCommandeTTC")
 */
class TotalTTC extends FieldPluginBase {

    /**
     * {@inheritdoc}
     */
    public function init(ViewExecutable $view, DisplayPluginBase $display, array &amp;$options = NULL) {
        parent::init($view, $display, $options);

    }

    /**
     * {@inheritdoc}
     */
    public function query() {
        }

    /**
     * {@inheritdoc}
     */
    public function render(ResultRow $values) {
       return 'test';
    }

}


I remove the query for this handler.

Then in my module file, i use the hook_views_data :

function boutique_views_data()
{

  $data['commandes_entity'] = array(

      'totalCommandeTTC' =&gt; array(
          'title' =&gt; t('Total Commande TTC'),
          'help' =&gt; t("Le total TTC des commandes"),
          'field' =&gt; array(
              'id' =&gt; 'totalCommandeTTC',
          ),


      ),

  );

return $data;
}


And the result in views after add the field with views ui :



The field is Total commande TTC.