class LanguageTestController in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/tests/language_test/src/Controller/LanguageTestController.php \Drupal\language_test\Controller\LanguageTestController
Controller routines for language_test routes.
Hierarchy
- class \Drupal\language_test\Controller\LanguageTestController implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of LanguageTestController
File
- core/
modules/ language/ tests/ language_test/ src/ Controller/ LanguageTestController.php, line 22 - Contains \Drupal\language_test\Controller\LanguageTestController.
Namespace
Drupal\language_test\ControllerView source
class LanguageTestController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The HTTP kernel service.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new LanguageTestController object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
* An HTTP kernel.
*/
public function __construct(HttpKernelInterface $httpKernel, LanguageManagerInterface $language_manager) {
$this->httpKernel = $httpKernel;
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('http_kernel'), $container
->get('language_manager'));
}
/**
* Route entity upcasting test helper.
*
* @param \Drupal\language\ConfigurableLanguageInterface $language
* The ConfigurableLanguage object from the route.
*
* @return string
* Testing feedback based on (translated) entity title.
*/
public function testEntity(ConfigurableLanguageInterface $configurable_language) {
return array(
'#markup' => $this
->t('Loaded %label.', array(
'%label' => $configurable_language
->label(),
)),
);
}
/**
* Returns links to the current page with different langcodes.
*
* Using #type 'link' causes these links to be rendered with the link
* generator.
*/
public function typeLinkActiveClass() {
// We assume that 'en' and 'fr' have been configured.
$languages = $this->languageManager
->getLanguages();
return array(
'no_language' => array(
'#type' => 'link',
'#title' => t('Link to the current path with no langcode provided.'),
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'attributes' => array(
'id' => 'no_lang_link',
),
'set_active_class' => TRUE,
),
),
'fr' => array(
'#type' => 'link',
'#title' => t('Link to a French version of the current path.'),
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'language' => $languages['fr'],
'attributes' => array(
'id' => 'fr_link',
),
'set_active_class' => TRUE,
),
),
'en' => array(
'#type' => 'link',
'#title' => t('Link to an English version of the current path.'),
'#url' => Url::fromRoute('<current>'),
'#options' => array(
'language' => $languages['en'],
'attributes' => array(
'id' => 'en_link',
),
'set_active_class' => TRUE,
),
),
);
}
/**
* Uses a sub request to retrieve the 'user' page.
*
* @return \Symfony\Component\HttpFoundation\Response
* The kernels response to the sub request.
*/
public function testSubRequest() {
$request = Request::createFromGlobals();
$server = $request->server
->all();
if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
// We need this for when the test is executed by run-tests.sh.
// @todo Remove this once run-tests.sh has been converted to use a Request
// object.
$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'];
$base_path = ltrim($server['REQUEST_URI'], '/');
}
else {
$base_path = $request
->getBasePath();
}
$sub_request = Request::create($base_path . '/user', 'GET', $request->query
->all(), $request->cookies
->all(), array(), $server);
return $this->httpKernel
->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageTestController:: |
protected | property | The HTTP kernel service. | |
LanguageTestController:: |
protected | property | The language manager service. | |
LanguageTestController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
LanguageTestController:: |
public | function | Route entity upcasting test helper. | |
LanguageTestController:: |
public | function | Uses a sub request to retrieve the 'user' page. | |
LanguageTestController:: |
public | function | Returns links to the current page with different langcodes. | |
LanguageTestController:: |
public | function | Constructs a new LanguageTestController object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |