You are here

class Populate in Prepopulate 8.2

Same name in this branch
  1. 8.2 src/Populate.php \Drupal\prepopulate\Populate
  2. 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

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_prepopulate
View 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

Namesort descending Modifiers Type Description Overrides
Populate::$currentUser protected property The current user.
Populate::$entityTypeManager protected property The entity type manager.
Populate::$moduleHandler protected property The module handler.
Populate::$request protected property The request stack.
Populate::$whitelistedTypes protected property The whitelisted element types that can be pre-populated.
Populate::formatEntityAutocomplete protected function Check access and properly format an autocomplete string. Overrides Populate::formatEntityAutocomplete
Populate::populateForm public function Populate form with values. Overrides PopulateInterface::populateForm
Populate::__construct public function Populate constructor. Overrides Populate::__construct