function TestSiteUserLoginCommand::execute

Same name in other branches
  1. 8.9.x core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand::execute()
  2. 10 core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand::execute()
  3. 11.x core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php \Drupal\TestSite\Commands\TestSiteUserLoginCommand::execute()

Throws

\Symfony\Component\Console\Exception\InvalidArgumentException

File

core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php, line 44

Class

TestSiteUserLoginCommand
Command to generate a login link for the test site.

Namespace

Drupal\TestSite\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
    $root = dirname(__DIR__, 5);
    chdir($root);
    $this->classLoader = (require 'autoload.php');
    $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
    $kernel::bootEnvironment();
    $kernel->setSitePath($input->getOption('site-path'));
    Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $this->classLoader);
    $request = Request::createFromGlobals();
    $kernel->boot();
    $kernel->preHandle($request);
    $container = $kernel->getContainer();
    $uid = $input->getArgument('uid');
    if (!is_numeric($uid)) {
        throw new InvalidArgumentException(sprintf('The "uid" argument needs to be an integer, but it is "%s".', $uid));
    }
    $userEntity = $container->get('entity_type.manager')
        ->getStorage('user')
        ->load($uid);
    $url = user_pass_reset_url($userEntity) . '/login';
    $output->writeln($url);
    return 0;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.