You are here

public function BusinessRulesUtil::getBundleEditableFields in Business Rules 8

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

Helper function to return all editable fields from one bundle.

Parameters

string $entityType: The entity type.

string $bundle: The entity bundle.

array $field_types_ids: Array of field types ids if you want to get specifics field types.

Return value

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

File

src/Util/BusinessRulesUtil.php, line 422

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function getBundleEditableFields($entityType, $bundle, array $field_types_ids = []) {
  if (empty($entityType) || empty($bundle)) {
    return [];
  }
  $fields = $this->entityFieldManager
    ->getFieldDefinitions($entityType, $bundle);
  $field_types = $this->fieldTypePluginManager
    ->getDefinitions();
  $options = [];
  foreach ($fields as $field_name => $field_storage) {

    // Do not show: non-configurable field storages but title.
    $field_type = $field_storage
      ->getType();
    if ($field_storage instanceof FieldConfig || $field_storage instanceof BaseFieldDefinition && $field_name == 'title') {
      if (count($field_types_ids) == 0 || in_array($field_type, $field_types_ids)) {
        $options[$field_name] = $this
          ->t('@type: @field', [
          '@type' => $field_types[$field_type]['label'],
          '@field' => $field_storage
            ->getLabel() . " [{$field_name}]",
        ]);
      }
    }
  }
  asort($options);
  return $options;
}