Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
    Bumped by Community user
3 edited tags
source | link

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 createset 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 ?

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 create 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 ?

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 ?

2 edited title
source | link

how How add fields programmatically to a custom entity bundle?

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 bundleall bundles ll automatically inherited fields from mother.

So i create 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 ?

how add fields programmatically to a custom entity bundle?

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 bundle ll automatically inherited fields from mother.

So i create 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 ?

How add fields programmatically to a custom entity bundle?

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 create 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 ?

1
source | link

how add fields programmatically to a custom entity bundle?

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 bundle ll automatically inherited fields from mother.

So i create 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 ?