protected FieldStorageAddForm::getExistingFieldLabels(array $field_names)
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.
File
- core/modules/field_ui/src/Form/FieldStorageAddForm.php, line 505
Class
- FieldStorageAddForm
- Provides a form for the "field storage" add page.
Namespace
Drupal\field_ui\Form
Code
protected function getExistingFieldLabels(array $field_names) {
// Get all the fields corresponding to the given field storage names and
// this entity type.
$field_ids = $this->queryFactory->get('field_config')
->condition('entity_type', $this->entityTypeId)
->condition('field_name', $field_names)
->execute();
$fields = $this->entityManager->getStorage('field_config')->loadMultiple($field_ids);
// Go through all the fields and use the label of the first encounter.
$labels = array();
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;
}
Please login to continue.