0

i create a custom Entity,

CustomEntity.php

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

    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('Name'))
      ->setSettings([
        'max_length' => 50,
        'text_processing' => 0,
      ])
      ->setDefaultValue('')
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => -4,
      ])
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -4,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);



    return $fields;
  }

We can add fields programmatically here for the Main entity and then all bundles ll automatically inherited fields from mother.

So i set a bundle in myModule/config/install:

myModule.customEntity.bundleA.yml

uuid: db129d12-849a-4e68-bb56-d787b4b0cf42
langcode: en
status: true
dependencies: {  }
id: bundleA
label: bundleA

I am looking for add fields programmatically to that bundle .

So i create with the admin interface all fields and have export all config files into my install folder. But it's a lot of files: storage / view / field / form.

Is there another way like the main entity for example ?

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.