Currently, the number field is added via BaseFieldDefinition, which doesn't allow the field to be configurable. We need to use hook_entity_field_info() to make this field configurable, so site admin can put their basic validation or change the precision of the field. For more information, please see https://www.drupal.org/docs/8/api/entity-api/defining-and-using-content-...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

skyredwang created an issue. See original summary.

dravenk’s picture

I've tried make points field configurable, but I can not finish it. I cant't change the precision of the field, but also can change the number of digits to the right of the points number.

dravenk’s picture

FileSize
2.27 KB

Move the points fields from the point table to points.module file

dravenk’s picture

Assigned: Unassigned » dravenk
Category: Task » Support request
Status: Active » Needs review
skyredwang’s picture

Category: Support request » Task
Status: Needs review » Needs work

The points field added in this patch is still non-configurable on /admin/structure/point_type/default/edit/fields

skyredwang’s picture

FileSize
55.58 KB

Attached screenshot shows what we want to achieve here. We want the site builder to be able to edit he points field settings, but not to delete it.

skyredwang’s picture

Below is the conversion I had with @berdir, which offers a solution to #6:

<skyred> berdir: ping
8:01 PM <berdir> skyred: pong
8:03 PM <skyred> berdir: I am porting Userspoints to Points in a sandbox project. Running int a road block, in D8, how can I programmatically add a base/default field to all Point Entity bundles, including the ones added by site admin, also I need this field to be configurable, but not delete-able. Like this screenshot: https://www.drupal.org/files/issues/Manage%20fields%20%7C%20Payment.png
8:03 PM <skyred> berdir: the example on the screenshot was done via config/install, which only works for existing bundle.
8:04 PM <berdir> skyred: why does it need to be always there but configurable?
8:11 PM <berdir> skyred: what you can do is the same node does with the body field. provide a non-deletable field storage default config, add the field when new bundles are created. use entity access th prevent deletion
8:13 PM <skyred> berdir: I am trying to add the core number field to every Point Entity bundle. I'd like it to be configurable, so the site admin can control the validation and precision. But, it cannot be deleted, so the rest of the module  can depend on it
8:14 PM <berdir> skyred: you could also have configuration that you use in a base field, that's better in terms of storage as it is then in the base table. it's not something that can be changed as soon as you have configuration anyway and they are storage settings, so can't be different per bundle either
dravenk’s picture

Category: Task » Feature request
Status: Needs work » Needs review

Done it. thanks.

dravenk’s picture

FileSize
4.35 KB
skyredwang’s picture

Status: Needs review » Fixed
skyredwang’s picture

Below is the same question I asked @bojanz, and his reply:

<skyred> bojanz: I am trying to add a locked field to a custom entity just like commerce did. But, I am using hook_entity_base_field_info() instead of config/install, but this way, I cannot see the fields on the custom entity/bundle/edit page, I can only see the fields on the form display and manage display page. Do you know a good example that I can look? 
6:23 PM <bojanz> skyred: commerce_shipping uses the same method to add store fields
7:05 PM <skyred> bojanz: I just looked at "/admin/commerce/config/store-types/online/edit/fields", the "Supported shipping countries" does not show. This is same on my project, too. Is this a bug? or by design
7:26 PM <bojanz> skyred: by design, that listing only shows configurable fields
7:27 PM <bojanz> skyred: you canćt edit a base field, it comes from code
7:48 PM <skyred> bojanz: the entity api docs says hook_entity_base_field_info produces a "configurable" field. Anyway, but how can I add a field to a certain entity with all bundles, I want the admin can configure the settings, but not delete the field?
9:09 PM <bojanz> skyred: then the docs are wrong. What you want can't be done
9:09 PM <bojanz> skyred: put your settings in the widget and have them configured there

  • skyredwang committed 0d6917b on 8.x-1.x
    Issue #2883735 by dravenk, skyredwang: Convert the number field to be...

  • skyredwang committed 4eea13b on 8.x-1.x
    Issue #2883735 by dravenk, skyredwang: Convert the number field to be...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.