protected function Populate::formatEntityAutocomplete in Prepopulate 8.2
Same name in this branch
- 8.2 src/Populate.php \Drupal\prepopulate\Populate::formatEntityAutocomplete()
- 8.2 modules/og_prepopulate/src/Populate.php \Drupal\og_prepopulate\Populate::formatEntityAutocomplete()
Check access and properly format an autocomplete string.
Parameters
string $value: The value.
array $element: The form element to populate.
Return value
string The formatted label if entity exists and view label access is allowed. Otherwise, the value.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to Populate::formatEntityAutocomplete()
- Populate::populateForm in src/
Populate.php - Populate form with values.
1 method overrides Populate::formatEntityAutocomplete()
- Populate::formatEntityAutocomplete in modules/
og_prepopulate/ src/ Populate.php - Check access and properly format an autocomplete string.
File
- src/
Populate.php, line 160
Class
- Populate
- Service to populate fields from URL.
Namespace
Drupal\prepopulateCode
protected function formatEntityAutocomplete($value, array &$element) {
$entity = $this->entityTypeManager
->getStorage($element['#target_type'])
->load($value);
if ($entity && $entity
->access('view label')) {
return "{$entity->label()} ({$value})";
}
return $value;
}