function FieldStorageAddForm::getExistingFieldLabels
Same name in other branches
- 8.9.x core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::getExistingFieldLabels()
Gets the human-readable labels for the given field storage names.
Since not all field storages are required to have a field, we can only provide the field labels on a best-effort basis (e.g. the label of a field storage without any field attached to a bundle will be the field name).
Parameters
array $field_names: An array of field names.
Return value
array An array of field labels keyed by field name.
1 call to FieldStorageAddForm::getExistingFieldLabels()
- FieldStorageAddForm::buildForm in core/
modules/ field_ui/ src/ Form/ FieldStorageAddForm.php - Form constructor.
File
-
core/
modules/ field_ui/ src/ Form/ FieldStorageAddForm.php, line 537
Class
- FieldStorageAddForm
- Provides a form for the "field storage" add page.
Namespace
Drupal\field_ui\FormCode
protected function getExistingFieldLabels(array $field_names) {
// Get all the fields corresponding to the given field storage names and
// this entity type.
$field_ids = $this->entityTypeManager
->getStorage('field_config')
->getQuery()
->condition('entity_type', $this->entityTypeId)
->condition('field_name', $field_names)
->execute();
$fields = $this->entityTypeManager
->getStorage('field_config')
->loadMultiple($field_ids);
// Go through all the fields and use the label of the first encounter.
$labels = [];
foreach ($fields as $field) {
if (!isset($labels[$field->getName()])) {
$labels[$field->getName()] = $field->label();
}
}
// For field storages without any fields attached to a bundle, the default
// label is the field name.
$labels += array_combine($field_names, $field_names);
return $labels;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.