Skip to content
Snippets Groups Projects
Unverified Commit def92d9f authored by Kevin Wenger's avatar Kevin Wenger Committed by GitHub
Browse files

fix Twig 1.38.x+ Attribute 'name' does not exists (#12)

fix Twig 1.38.x+ Attribute 'name' does not exists
parents 8967a779 534b16b3
No related branches found
No related tags found
No related merge requests found
......@@ -123,6 +123,7 @@ before_script:
- composer require "symfony/process:^3.4" --no-interaction --working-dir=${TRAVIS_BUILD_DIR}/../drupal-8/drupal
script:
- export SYMFONY_DEPRECATIONS_HELPER=disabled
- drupal-ti script
after_script:
......
......@@ -59,6 +59,9 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface {
*
* @return \Drupal\potion\MessageCatalogue
* Catalogue of extracted translations messages.
*
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
protected function extractFromTemplate($template) {
/** @var \Drupal\potion\Twig\NodeVisitor\TranslationNodeVisitor $visitor */
......@@ -78,7 +81,7 @@ class TwigExtractor extends ExtractorBase implements ExtractableInterface {
* @param string $directory
* Directory to dig in.
* @param bool $recursive
* Enable or disable scan with recusrsion.
* Enable or disable scan with recursion.
*
* @return \Iterator|SplFileInfo[]
* An iterator.
......
......@@ -5,6 +5,7 @@ namespace Drupal\potion\Twig\NodeVisitor;
use Drupal\Core\Template\TwigNodeTrans;
use Twig\NodeVisitor\AbstractNodeVisitor;
use Drupal\potion\MessageCatalogue;
use Twig\Node\CheckToStringNode;
/**
* Extracts translation messages from twig.
......@@ -172,7 +173,7 @@ class TranslationNodeVisitor extends AbstractNodeVisitor {
}
/**
* Extracts the text for complexe form of "trans" tag.
* Extracts the text for complex form of "trans" tag.
*
* @param \Twig_Node $body
* The node to compile.
......@@ -180,6 +181,8 @@ class TranslationNodeVisitor extends AbstractNodeVisitor {
* @return string
* The translations strings.
*
* @throws \Twig_Error_Syntax
*
* @see \Drupal\Core\Template\TwigNodeTrans::compileString
*/
protected function compileString(\Twig_Node $body) {
......@@ -196,6 +199,9 @@ class TranslationNodeVisitor extends AbstractNodeVisitor {
$n = $n->getNode('node');
}
if ($n instanceof CheckToStringNode) {
$n = $n->getNode('expr');
}
$args = $n;
// Support TwigExtension->renderVar() function in chain.
......@@ -205,25 +211,25 @@ class TranslationNodeVisitor extends AbstractNodeVisitor {
// Detect if a token implements one of the filters reserved for
// modifying the prefix of a token. The default prefix used for
// translations is "@". This escapes the printed token and makes
// them // safe for templates.
// translations is "@". This escapes the printed token and makes them
// safe for templates.
// @see TwigExtension::getFilters()
$argPrefix = '@';
while ($args instanceof \Twig_Node_Expression_Filter) {
switch ($args->getNode('filter')->getAttribute(
'value'
)) {
switch ($args->getNode('filter')->getAttribute('value')) {
case 'placeholder':
$argPrefix = '%';
break;
}
$args = $args->getNode('node');
}
if ($args instanceof CheckToStringNode) {
$args = $args->getNode('expr');
}
if ($args instanceof \Twig_Node_Expression_GetAttr) {
$argName = [];
// Assemble a valid argument name by walking through expression.
$argName[] = $args->getNode('attribute')
->getAttribute('value');
$argName[] = $args->getNode('attribute')->getAttribute('value');
while ($args->hasNode('node')) {
$args = $args->getNode('node');
if ($args instanceof \Twig_Node_Expression_Name) {
......
......@@ -90,7 +90,9 @@ class TranslationsExportTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsExport::exportFromDatabase
*/
public function testExportInvalidLangcode() {
$this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->translationExport->exportFromDatabase('ru');
}
......
......@@ -104,7 +104,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsExtractor::extract
*/
public function testExtractSourceNotFound() {
$this->setExpectedException(PotionException::class, "No such file or directory temporary://not-found");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("No such file or directory temporary://not-found");
$this->translationExtractor->extract('fr', 'temporary://not-found', TRUE);
}
......@@ -117,7 +118,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase {
$this->fileSystem->prepareDirectory($dest, FILE_CREATE_DIRECTORY);
@chmod($dest, 0000);
$this->setExpectedException(PotionException::class, "The path temporary://not-readable is not readable.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("The path temporary://not-readable is not readable.");
$this->translationExtractor->extract('fr', 'temporary://not-readable', TRUE);
}
......@@ -125,7 +127,8 @@ class TranslationsExtractorTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsExtractor::extract
*/
public function testExtractInvalidLangcode() {
$this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->translationExtractor->extract('ru', $this->extractionPath, TRUE);
}
......
......@@ -55,7 +55,8 @@ class TranslationsFillTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsFill::fillFromDatabase
*/
public function testSourceNotFound() {
$this->setExpectedException(PotionException::class, "No such file or directory temporary://not-found");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("No such file or directory temporary://not-found");
$this->translationsFill->fillFromDatabase('fr', 'temporary://not-found');
}
......@@ -63,7 +64,8 @@ class TranslationsFillTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsFill::fillFromDatabase
*/
public function testInvalidPo() {
$this->setExpectedException(PotionException::class, "File modules/contrib/potion/tests/modules/potion_test/assets/malformed/missing-msgid.po is a malformed .po file.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("File modules/contrib/potion/tests/modules/potion_test/assets/malformed/missing-msgid.po is a malformed .po file.");
$source = $this->translationsPath . '/malformed/missing-msgid.po';
$this->translationsFill->fillFromDatabase('fr', $source);
......@@ -73,7 +75,8 @@ class TranslationsFillTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsFill::fillFromDatabase
*/
public function testInvalidLangcode() {
$this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it.");
$source = $this->translationsPath . '/fr.po';
$this->translationsFill->fillFromDatabase('ru', $source);
......
......@@ -298,7 +298,8 @@ class TranslationsImportTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsImport::importFromFile
*/
public function testInvalidPo() {
$this->setExpectedException(PotionException::class, "File modules/contrib/potion/tests/modules/potion_test/assets/malformed/missing-msgid.po is a malformed .po file.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("File modules/contrib/potion/tests/modules/potion_test/assets/malformed/missing-msgid.po is a malformed .po file.");
$source = $this->translationsPath . '/malformed/missing-msgid.po';
$this->translationsImport->importFromFile('fr', $source);
......@@ -308,7 +309,8 @@ class TranslationsImportTest extends TranslationsTestsBase {
* @covers \Drupal\potion\TranslationsImport::importFromFile
*/
public function testInvalidLangcode() {
$this->setExpectedException(PotionException::class, "The langcode ru is not defined. Please create & enabled it before trying to use it.");
$this->expectException(PotionException::class);
$this->expectExceptionMessage("The langcode ru is not defined. Please create & enabled it before trying to use it.");
$source = $this->translationsPath . '/fr.po';
$this->translationsImport->importFromFile('ru', $source);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment