class MachineNameController in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/MachineNameController.php \Drupal\system\MachineNameController
Controller routines for machine name transliteration routes.
Hierarchy
- class \Drupal\system\MachineNameController implements ContainerInjectionInterface
Expanded class hierarchy of MachineNameController
1 file declares its use of MachineNameController
- MachineNameControllerTest.php in core/
modules/ system/ tests/ src/ Unit/ Transliteration/ MachineNameControllerTest.php - Contains \Drupal\Tests\system\Unit\Transliteration\MachineNameControllerTest.
File
- core/
modules/ system/ src/ MachineNameController.php, line 20 - Contains \Drupal\system\MachineNameController.
Namespace
Drupal\systemView source
class MachineNameController implements ContainerInjectionInterface {
/**
* The transliteration helper.
*
* @var \Drupal\Component\Transliteration\TransliterationInterface
*/
protected $transliteration;
/**
* Constructs a MachineNameController object.
*
* @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
* The transliteration helper.
*/
public function __construct(TransliterationInterface $transliteration) {
$this->transliteration = $transliteration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('transliteration'));
}
/**
* Transliterates a string in given language. Various postprocessing possible.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The input string and language for the transliteration.
* Optionally may contain the replace_pattern, replace, lowercase parameters.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* The transliterated string.
*/
public function transliterate(Request $request) {
$text = $request->query
->get('text');
$langcode = $request->query
->get('langcode');
$replace_pattern = $request->query
->get('replace_pattern');
$replace = $request->query
->get('replace');
$lowercase = $request->query
->get('lowercase');
$transliterated = $this->transliteration
->transliterate($text, $langcode, '_');
if ($lowercase) {
$transliterated = Unicode::strtolower($transliterated);
}
if (isset($replace_pattern) && isset($replace)) {
// Quote the pattern delimiter and remove null characters to avoid the e
// or other modifiers being injected.
$transliterated = preg_replace('@' . strtr($replace_pattern, [
'@' => '\\@',
chr(0) => '',
]) . '@', $replace, $transliterated);
}
return new JsonResponse($transliterated);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MachineNameController:: |
protected | property | The transliteration helper. | |
MachineNameController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
MachineNameController:: |
public | function | Transliterates a string in given language. Various postprocessing possible. | |
MachineNameController:: |
public | function | Constructs a MachineNameController object. |