1

In Drupal 8, I am using the Config Pages module to set up a configuration page for a custom module. How can I add all the existing content types into a dropdown list?

1 Answer 1

0

In your custom form, in add $options to your content type list field. the following snippet get list of all the content type names for you;

   $node_types = \Drupal\node\Entity\NodeType::loadMultiple();
    // If you need to display them in a drop down:
    $options = [];
    foreach ($node_types as $node_type) {
      $options[$node_type->id()] = $node_type->label();
    }

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.