Last active
June 24, 2022 02:38
-
-
Save Greg-Boggs/279f6f515717d1abaea4837613edf711 to your computer and use it in GitHub Desktop.
Get a list of all fields in Drupal 9/10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get all Node types and all fields | |
$content_types = NodeType::loadMultiple(); | |
foreach ($content_types as $content_type) { | |
$types_options[$content_type->id()] = $content_type->label(); | |
foreach (\Drupal::service('entity_field.manager')->getFieldDefinitions('node', $content_type->id()) as $field_name => $field_definition) { | |
if (!empty($field_definition->getTargetBundle())) { | |
$field_options[$field_definition->getName() . ':' . $field_name] = $field_definition->getLabel(); | |
//display content type names in the drop down | |
//$field_options[(string) $content_type->label()][$field_definition->getName() . ':' . $field_name] = $field_definition->getLabel(); | |
} | |
} | |
} | |
asort($field_options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment