HostsSetterController.php in Lingotek Translation 3.2.x
Same filename and directory in other branches
- 8.2 tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 4.0.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.0.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.1.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.3.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.4.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.5.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.6.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.7.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
- 3.8.x tests/modules/lingotek_test/src/Controller/HostsSetterController.php
Namespace
Drupal\lingotek_test\ControllerFile
tests/modules/lingotek_test/src/Controller/HostsSetterController.phpView source
<?php
namespace Drupal\lingotek_test\Controller;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller for pointing up the host and sandbox in config to the local site.
*
* This is needed as workaround, as we need to reference the local site from
* configuration but it isn't possible from yaml files or without a valid HTTP
* request.
*
* @package Drupal\lingotek_test\Controller
*/
class HostsSetterController extends ControllerBase {
/**
* Constructs the HostsSetterController object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
/**
* Helper method for setting up a valid host for testing.
*
* Required for the workbench links.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response with the current basepath and a success message.
*/
public function setHosts(Request $request) {
$basepath = $request
->getSchemeAndHttpHost();
$config = $this->configFactory
->getEditable('lingotek.settings');
$config
->set('account.use_production', TRUE)
->set('account.sandbox_host', $basepath)
->set('account.host', $basepath);
$config
->save();
return new JsonResponse([
'message' => 'Success setting host to ' . $basepath,
'basepath' => $basepath,
]);
}
}
Classes
Name | Description |
---|---|
HostsSetterController | Controller for pointing up the host and sandbox in config to the local site. |