Form submit in FieldFormatter I have a custom entity type with a "yield" field. I would like to allow users to see the custom entity (full content view-mode) and change "yield" value to regenerate it with calculated values from the yield changement.

I started with a new fieldFormatter for my "yield" (number_decimal) field. The formatter extends DecimalFormatter and builds a little form object instead of displaying a simple markup.

$element = [
  '#type' =&gt; 'form',
  '#tree' =&gt; TRUE,
];
$element['yield'] = [
  '#type' =&gt; 'number',
  '#title' =&gt; $this-&gt;t('Change yield'),
  '#default_value' =&gt; floatval($this-&gt;numberFormat($item-&gt;value)),
  '#value' =&gt; floatval($this-&gt;numberFormat($item-&gt;value)),
];

$element['submit'] = [
  '#type' =&gt; 'submit',
  '#value' =&gt; $this-&gt;t('Change'),
  '#submit' =&gt; ['changeYield'],
];


Form is defined in the full content view, and a click on the submit button send the form. I think this is not the correct way to add a form because #submit callback is never called. I tried different syntax, with static or non-static callback, but it doesn't work.

I would like to find an elegant solution, not hacking and adding JavaScript custom code.

Now the ideal solution is attaching #ajax callback to rebuild the data without sending the page, but I don't know if it possible and if dependencies will be not to strong, because changes done on another fieldFormatter item's values.
You can't add a form field to an entity display. You have to approach this the other way. Build a form class with the field and the submit button and add the entity content to it. Then you can respond to the posted data in the submit method of the form class and save it to the entity.

For the ideal solution you can attach ajax to the submit button to avoid a page reload.

An alternative option is an entity form using a custom form mode containing one field. This could be set up without code by using blocks for both, the entity content and entity form or only one of them and the other as page. This depends on what the end result should look like. You need a module to control the form modes Form mode control and to put an entity form in a block Entityform block. The entity content can be placed in a block with Views. For a custom entity all of this can be done in code as well.