You are here

public function BusinessRulesUtil::getBundleFields in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Util/BusinessRulesUtil.php \Drupal\business_rules\Util\BusinessRulesUtil::getBundleFields()

Helper function to return all fields from one bundle.

Parameters

string $entityType: The entity type.

string $bundle: The entity bundle.

Return value

array Array of fields ['type' => 'description']

File

src/Util/BusinessRulesUtil.php, line 389

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function getBundleFields($entityType, $bundle) {
  if (empty($entityType) || empty($bundle)) {
    return [];
  }
  $fields = $this->entityFieldManager
    ->getFieldDefinitions($entityType, $bundle);
  foreach ($fields as $field_name => $field_storage) {
    $field_type = $field_storage
      ->getType();
    $options[$field_name] = $this
      ->t('@type: @field', [
      '@type' => $field_type,
      '@field' => $field_storage
        ->getLabel() . " [{$field_name}]",
    ]);
  }
  asort($options);
  return $options;
}