Skip to content
Snippets Groups Projects

Fix phpstan issues

5 files
+ 28
5
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -8,6 +8,7 @@ use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup;
use Drupal\Core\Session\AccountInterface;
use Drupal\select2\Select2Trait;
use Drupal\user\EntityOwnerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -35,12 +36,20 @@ class Select2EntityReferenceWidget extends Select2Widget {
*/
protected $entityTypeManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
$widget = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$widget->setEntityTypeManager($container->get('entity_type.manager'));
$widget->setCurrentUser($container->get('current_user'));
return $widget;
}
@@ -54,6 +63,16 @@ class Select2EntityReferenceWidget extends Select2Widget {
$this->entityTypeManager = $entityTypeManager;
}
/**
* Set the current user.
*
* @param \Drupal\Core\Session\AccountInterface $currentUser
* The current user.
*/
protected function setCurrentUser(AccountInterface $currentUser): void {
$this->currentUser = $currentUser;
}
/**
* {@inheritdoc}
*/
@@ -163,7 +182,7 @@ class Select2EntityReferenceWidget extends Select2Widget {
$entity = $items->getEntity();
$element['#autocreate'] = [
'bundle' => $bundle,
'uid' => ($entity instanceof EntityOwnerInterface) ? $entity->getOwnerId() : \Drupal::currentUser()->id(),
'uid' => ($entity instanceof EntityOwnerInterface) ? $entity->getOwnerId() : $this->currentUser->id(),
];
}
// Do not display a 'multiple' select box if there is only one option. But
Loading