sstEntityTypeBundleInfo)) { $this->sstEntityTypeBundleInfo = \Drupal::service('entity_type.bundle.info'); } return $this->sstEntityTypeBundleInfo; } protected function getEntityFieldManager() { if (!isset($this->sstEntityFieldManager)) { $this->sstEntityFieldManager = \Drupal::service('entity_field.manager'); } return $this->sstEntityFieldManager; } protected function getEntityType() { assert(isset($this->sstEntityType)); return $this->sstEntityType; } /** * {@inheritdoc} */ public function fields() { $bundles = $this->getEntityTypeBundleInfo() ->getBundleInfo($typeName = $this->getEntityType()); $rows = []; foreach ($bundles as $bundleName => $bundle) { $fieldDefinitions = $this->getEntityFieldManager() ->getFieldDefinitions($typeName, $bundleName); foreach ($fieldDefinitions as $fieldName => $fieldDefinition) { $rows[$fieldName][$bundleName] = $fieldDefinition->getLabel(); } } $fields = []; $singleBundle = count($bundles) === 1; foreach ($rows as $fieldName => $labels) { if ($singleBundle) { $fields[$fieldName] = reset($labels); continue; } if (count(array_unique($labels)) === 1) { $fields[$fieldName] = reset($labels); continue; } $ret = []; ksort($labels); foreach ($labels as $ct => $label) { $ret[] = $this->t('@ct: @label', ['@ct' => $ct, '@label' => $label]); } $fields[$fieldName] = implode(', ', $ret); } ksort($fields); return $fields; } }