Custom content entity: can't hide translation details in edit form I've created a multi-lingual custom content entity using Drupal Console. The basic stuff with editing/viewing works fine, also multi-lingual. But for some reason, I can't hide the "Translation" details form element (the one with the translation meta data) in the entity's edit form.

Screenshot of form display settings:


Screenshot of edit form:


In the config export core.entity_form_display.chunk.weather_daswetter.default.yml the translation also is listed correctly in the hidden section:

id: chunk.weather_daswetter.default
targetEntityType: chunk
bundle: weather_daswetter
mode: default
third_party_settings:
  stuff_from_field_group_module_here: nothing_with_translation
content:
  all_visible_fields_listed_correctly
hidden:
  changed: true
  created: true
  langcode: true
  translation: true
  uid: true


Into the blue I've tried relisting the fields from core's ContentTranslationHandler in my own src/Entity/Chunk.php-&gt;baseFieldDefinitions() and explicitly set them configurable, but this did not help either:

/**
 * @ContentEntityType(
 *   id = "chunk",
 *    ...
 *   translatable = TRUE,
 *   ...
 * )
 */
class Chunk extends ContentEntityBase implements ChunkInterface {
  use EntityOwnerTrait;
  use EntityChangedTrait;
  use EntityPublishedTrait;

  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields += static::publishedBaseFieldDefinitions($entity_type);

    // tried adding this, did not help
    if ($fields['content_translation_status']) {
      $fields['content_translation_status']-&gt;setDisplayConfigurable('form', TRUE);
    }

    if ($fields['content_translation_outdated']) {
      $fields['content_translation_outdated']-&gt;setDisplayConfigurable('form', TRUE);
    }

    if ($fields['content_translation_uid']) {
      $fields['content_translation_uid']-&gt;setDisplayConfigurable('form', TRUE);
    }

    if ($fields['content_translation_created']) {
      $fields['content_translation_created']-&gt;setDisplayConfigurable('form', TRUE);
    }
  }
}


Why doesn't the form display mode control for "Translation" work?

I really want to keep this visible and configurable in the UI and therefore want to avoid using hook_form_alter.

UPDATE:
I've tried using hook_form_alter, but this doesn't work either:


function wt_chunks_form_alter(&amp;$form, $form_state, $form_id) {
  if ($form['#entity_type'] == 'chunk') {
    /** @var $formMode \Drupal\Core\Entity\Entity\EntityFormDisplay */
    $formMode = $form_state-&gt;getStorage()['form_display'];
    $hiddenFields = $formMode-&gt;get('hidden');
    if (in_array('translation', $hiddenFields)) {
      //code goes into here, but the key 'content_translation' 
      //does not exist in the $form array
      $form['content_translation']['#access'] = FALSE;
    }
  }
}
The translation field that you try to disable is not the one containing the metadata.

The translation metadata is generated in Drupal\content_translation\ContentTranslationHandler and is automatically applied if following access check is true:

'#access' =&gt; $this-&gt;getTranslationAccess($entity, $new_translation ? 'create' : 'update')-&gt;isAllowed(),


To solve this problem you can add a checkbox to your entity settings form that allows you to disable the translation.

You will also need to create a custom TranslationHandler for you entity.

In the annotations of your entity add this under handlers:

"translation" = "Drupal\MY_MODULE\MyEntityTranslationHandler",


Your custom translation handler can then be something like this:

namespace Drupal\MY_MODULE;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;

class MyEntityTranslationHandler extends ContentTranslationHandler {

  public function entityFormAlter(array &amp;$form, FormStateInterface $form_state, EntityInterface $entity) {
    $form = parent::entityFormAlter($form, $form_state, $entity);
    if (// Some condition...) {
      $form['content_translation']['#access'] = FALSE;
    }
  }

}


Hope it makes sense.