I'm pretty new to Drupal, I come from Wordpress development and I'm trying to "translate" some of my plugins to modules in Drupal 8.
I'm following the documentation trying to add a new field, say "price" to a node. All the documentation I found is related to add a field to a custom node, but in my case I want to add those fields to normal predefined nodes.
First question that comes to my mind is, I can create the custom field with YML configuration files or code right?
I created the field with YML and it is recognised by drupal; the problem is that they don't appear on the nodes (I have to manually activate it).
I created on my module /config/install/:
- core.entity_form_display.node.article.default
- core.entity_view_display.node.article.default
I add my field, but of course when I try to activate the module it does not like it since they are already defined by Drupal.
Is there a way to "extend" those core files? is that possible with YML or code?
I followed https://www.drupal.org/docs/8/api/entity-api/programming-custom-fields-into-your-content-type. I created the YML files on /config/install, and indeed the field is created, the problem is I don't know how to "extend" view and form display entities as they are not related to a custom node type, otherwise they should be linked to pre-built node types and I cannot redefine those files (core.entity_form_display.node.article.default core.entity_view_display.node.article.default) since they already exist on the core.
Following this comment I've created the following files:
/config/install/field.field.node.article.field_price.yml
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_price
- node.type.article
id: node.article.field_price
field_name: field_price
entity_type: node
bundle: article
label: Price
description: 'Premium Price'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
min: 1
max: 9999
prefix: ''
suffix: ''
field_type: integer
/config/install/field.storage.node.field_price.yml
langcode: en
status: true
dependencies:
module:
- node
id: node.field_price
field_name: field_price
entity_type: node
type: integer
settings:
unsigned: false
size: normal
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Also I created FieldFormatter and FieldWidget. (I am not sure if properly.)
What I found out is the module is creating the field Price. If I go to /admin/structure/types/manage/article/display, I see my price there, but it is under Disabled.
I feel I'm so close, but at the same time so lost.
What am I missing in order to make that field go active?