I am creating a custom form and want to render the form field using the FieldStorageConfig and FieldConfig. Fields (my_field) could be any type those are supported by FormAPI.

$field = FieldStorageConfig::loadByName('node', 'my_field');
$field_instance = FieldConfig::loadByName('node', 'my_content_type', 'my_field');

$form['duplicate'] = [
  '#title' => 'Get the title form my_field',
  '#type' => 'Get the type form my_field',
  '#other_properties' => 'Get all form element properties'

  • A Field in Drupal is not a 1:1 mapping of form fields in Form API.
    – Kevin
    May 8 at 14:51
  • Thanks, @Kevin Is there any quick way to achieve this? Otherwise, I'll create a form using FormAPI. May 8 at 15:38
  • An entity field has a widget that specifies how the field appears in edit forms. That is what should be used to render an entity field in an edit form. As a side note, not all the entity fields use FieldConfig as their class.
    – apaderno
    May 22 at 21:01


Your Answer

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

Browse other questions tagged or ask your own question.