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
Overrides Populate::formatEntityAutocomplete
File
- modules/
og_prepopulate/ src/ Populate.php, line 47
Class
- Populate
- Service to populate og audience fields from URL.
Namespace
Drupal\og_prepopulateCode
protected function formatEntityAutocomplete($value, array &$element) {
$entity = $this->entityTypeManager
->getStorage($element['#target_type'])
->load($value);
if ($entity && Og::isMember($entity, $this->currentUser
->getAccount())) {
$element['#value'] = "{$entity->label()} ({$value})";
$element['#access'] = FALSE;
}
}