I have created a custom field and I wish to load the value dynamically in another form in relation to the specific node entity the value belongs to. I understand that to get the value I have to use/know the field_name like this


What I want is to get the field_name set via content configurations with only the type of node and the field name as defined in the fieldItem Plugin

$field_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('node');

When I dump $field_definitions am able to see all the fields array with all the details but I can't get my node.field_name in relation to the fieldItem name defined in the specific field plugin, in my case field_custom_example

 * Plugin implementation of the 'field_custom_example' field type.
 * @FieldType(
 *   id = "field_custom_example",
 *   label = @Translation("Custom Example"),
 *   description = @Translation("Stores data for Custom Example Field"),
 *   default_widget = "custom_example_widget",
 *   default_formatter = "custome_example_formatter"
 * )

that's where am stuck.

1 Answer 1


Use the method FieldDefinitionInterface::getType:

Returns the field type.

Return value

(string) The field type, i.e. the id of a field type plugin. For example 'text'.

In your case for example:

foreach ($field_definitions as $name => $definition) {
  if ($definition->getType() == 'field_custom_example') {
    // found field $name
  • thanks alot for pointing me that way..I could upvote the answer..but unfortunately am not qualified yet..am grateful.
    – Nicholas
    Nov 23, 2018 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.