class Populate in Prepopulate 8.2
Same name in this branch
- 8.2 src/Populate.php \Drupal\prepopulate\Populate
- 8.2 modules/og_prepopulate/src/Populate.php \Drupal\og_prepopulate\Populate
Service to populate og audience fields from URL.
@package Drupal\og_prepopulate
Hierarchy
- class \Drupal\prepopulate\Populate implements PopulateInterface
- class \Drupal\og_prepopulate\Populate
Expanded class hierarchy of Populate
1 string reference to 'Populate'
- og_prepopulate.services.yml in modules/
og_prepopulate/ og_prepopulate.services.yml - modules/og_prepopulate/og_prepopulate.services.yml
1 service uses Populate
- og_prepopulate.populator in modules/
og_prepopulate/ og_prepopulate.services.yml - Drupal\og_prepopulate\Populate
File
- modules/
og_prepopulate/ src/ Populate.php, line 17
Namespace
Drupal\og_prepopulateView source
class Populate extends BasePopulate {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Populate constructor.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request
* The request.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user.
*/
public function __construct(RequestStack $request, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountProxyInterface $current_user) {
$populator = parent::__construct($request, $entity_type_manager, $module_handler);
$this->currentUser = $current_user;
return $populator;
}
/**
* {@inheritdoc}
*/
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;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Populate:: |
protected | property | The current user. | |
Populate:: |
protected | property | The entity type manager. | |
Populate:: |
protected | property | The module handler. | |
Populate:: |
protected | property | The request stack. | |
Populate:: |
protected | property | The whitelisted element types that can be pre-populated. | |
Populate:: |
protected | function |
Check access and properly format an autocomplete string. Overrides Populate:: |
|
Populate:: |
public | function |
Populate form with values. Overrides PopulateInterface:: |
|
Populate:: |
public | function |
Populate constructor. Overrides Populate:: |