public function Services::getEntityTypesAndBundles in Wysiwyg API template plugin 3.0.x
File
- src/
Services.php, line 35
Class
Namespace
Drupal\wysiwyg_templateCode
public function getEntityTypesAndBundles() {
$entity_types = [];
foreach ($this->entityTypeManager
->getDefinitions() as $definition) {
if ($definition instanceof ContentEntityTypeInterface) {
$bundles = array_keys($this->bundleInfo
->getBundleInfo($definition
->id()));
if (empty($bundles)) {
$bundles = [
$definition
->id(),
];
}
$entity_types[$definition
->id()] = [
'label' => $definition
->getLabel(),
'bundles' => [],
];
foreach ($bundles as $bundle) {
$text_fields = [];
foreach ($this->entityFieldManager
->getFieldDefinitions($definition
->id(), $bundle) as $fieldDefinition) {
if (in_array($fieldDefinition
->getType(), [
'text',
'text_long',
'text_with_summary',
])) {
$text_fields[] = $fieldDefinition;
}
}
if (!empty($text_fields)) {
$entity_types[$definition
->id()]['bundles'][$bundle] = [
'label' => $bundle,
'fields' => $text_fields,
];
}
}
}
}
return $entity_types;
}