Score:0

Adding custom field generated by drush to available fields on node

us flag

I have an existing custom module on my D9 website and I need to make some changes inside it. I want to add a field (boolean) into any content type page edit without doing it manually.

So I need my field to be available here /admin/structure/types/manage/mycontenttype/fields/add-field

On my CLI, i've run this command drush generate field, which gave me those files :

  modules/custom/mymdule/config/schema/calcul.schema.yml
  modules/custom/mymdule/css/calcul-ajout-widget.css
  modules/custom/mymdule/calcul.libraries.yml
  modules/custom/mymdule/src/Plugin/Field/FieldFormatter/AjoutDefaultFormatter.php
  modules/custom/mymdule/src/Plugin/Field/FieldType/AjoutItem.php
  modules/custom/mymdule/src/Plugin/Field/FieldWidget/AjoutWidget.php

After, I ran drush updb, but it said that the database is already up to date. Yet, I don't see my field here. Moreover, the command didn't asked me what entity type should be linked to this field.

Any thoughts ? What i've done wrong ?

enter image description here

leymannx avatar
ne flag
Why don't you use configuration management?
leymannx avatar
ne flag
Does this answer your question? [add field to user in hook\_update\_n](https://drupal.stackexchange.com/questions/307964/add-field-to-user-in-hook-update-n)
mt.i.1 avatar
us flag
@leymannx because I'd like to do it programmaticaly, if it's possible. I have a certain amount of entity type, so it could be time consuming... and I don't think your solution is the same than my problem
4uk4 avatar
cn flag
The drush command is for modules which want to define a new field type. A prominent example is the [Address](https://www.drupal.org/project/address) module. Once you have installed such a module you see the field type on the left side, not the right. The right select box is filled with fields already used in other content types so that you can re-use them to save database tables.
mt.i.1 avatar
us flag
Oh, ok thanks for the precison ! Indeed, I see my left select dropdow.
mt.i.1 avatar
us flag
Maybe you should post your comment as an answer
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.