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
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();
}