Drupal-console: [create:vocabularies] ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences()

Created on 15 Apr 2017  路  12Comments  路  Source: hechoendrupal/drupal-console

Tried creating vocabularies with 8.4.x but this didn't work:

$ drupal create:vocabularies

 // Welcome to the Drupal vocabularies creator

 Enter how many vocabularies would you like to create [25]:
 > 

 Enter the maximum number of words in vocabulary names [5]:
 > 

ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php on line 192 #0 /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php(61): Drupal\Component\Utility\Random->sentences()
#1 /var/www/html/drucker/docroot/vendor/drupal/console/src/Command/Create/VocabulariesCommand.php(102): Drupal\Console\Utils\Create\VocabularyData->create(25, 5)
#2 phar:///usr/local/bin/drupal/vendor/symfony/console/Command/Command.php(264): Drupal\Console\Command\Create\VocabulariesCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php(868): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Drupal\Console\Command\Create\VocabulariesCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/drucker/docroot/vendor/drupal/console-core/src/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/drucker/docroot/vendor/drupal/console/src/Application.php(49): Drupal\Console\Core\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 phar:///usr/local/bin/drupal/vendor/symfony/console/Application.php(122): Drupal\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/drucker/docroot/vendor/drupal/console/bin/drupal.php(69): Symfony\Component\Console\Application->run()
#9 phar:///usr/local/bin/drupal/src/Utils/Launcher.php(30): include_once('/var/www/html/d...')
#10 phar:///usr/local/bin/drupal/bin/drupal.php(86): Drupal\Console\Launcher\Utils\Launcher->launch('/var/www/html/d...', Object(Composer\Autoload\ClassLoader))
#11 phar:///usr/local/bin/drupal/bin/drupal(3): require('phar:///usr/loc...')
#12 /usr/local/bin/drupal(10): require('phar:///usr/loc...')
#13 {main}
ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in Drupal\Component\Utility\Random->sentences() (line 192 of /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php).

I also tried other values than the default values, but this doesn't work any better. It always fail on Enter the maximum number of words in vocabulary names

$ composer show | grep drupal/console
drupal/console                        1.0.0-rc16         The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
drupal/console-core                   1.0.0-rc16         Drupal Console Core
drupal/console-en                     1.0.0-rc16         Drupal Console English Language
drupal/console-extend-plugin          0.4.0              Drupal Console Extend Plugin
$ drupal --version
Drupal Console version 1.0.0-rc16
bug

Most helpful comment

@anavarre can you try drupal cr all

I tested on master and is fixed, make sure you test it with next release ETA this week.

All 12 comments

@anavarre can you try drupal cr all

I tested on master and is fixed, make sure you test it with next release ETA this week.

Unfortunately I'm still seeing the issue even after upgrading (also rebuilt caches just in case)

 $ drupal --version
Drupal Console version 1.0.0-rc17
$ drupal create:vocabularies

 // Welcome to the Drupal vocabularies creator

 Enter how many vocabularies would you like to create [25]:
 > 

 Enter the maximum number of words in vocabulary names [5]:
 > 

ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php on line 192 #0 /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php(61): Drupal\Component\Utility\Random->sentences()
#1 /var/www/html/drucker/docroot/vendor/drupal/console/src/Command/Create/VocabulariesCommand.php(102): Drupal\Console\Utils\Create\VocabularyData->create(25, 5)
#2 /var/www/html/drucker/docroot/vendor/symfony/console/Command/Command.php(267): Drupal\Console\Command\Create\VocabulariesCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(872): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Drupal\Console\Command\Create\VocabulariesCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/drucker/docroot/vendor/drupal/console-core/src/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/drucker/docroot/vendor/drupal/console/src/Application.php(49): Drupal\Console\Core\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(122): Drupal\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/drucker/docroot/vendor/drupal/console/bin/drupal.php(68): Symfony\Component\Console\Application->run()
#9 phar:///usr/local/bin/drupal/src/Utils/Launcher.php(30): include_once('/var/www/html/d...')
#10 phar:///usr/local/bin/drupal/bin/drupal.php(52): Drupal\Console\Launcher\Utils\Launcher->launch('/var/www/html/d...')
#11 phar:///usr/local/bin/drupal/bin/drupal(3): require('phar:///usr/loc...')
#12 /usr/local/bin/drupal(10): require('phar:///usr/loc...')
#13 {main}
ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in Drupal\Component\Utility\Random->sentences() (line 192 of /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php).

@anavarre can you change directory out of the drupal site and execute drupal self-update

Tried updating to RC18 and ran drupal self-update but I'm still getting the same exact issue.

$ drupal --version          
Drupal Console version 1.0.0-rc18
$ drupal create:vocabularies

 // Welcome to the Drupal vocabularies creator

 Enter how many vocabularies would you like to create [25]:
 > 

 Enter the maximum number of words in vocabulary names [5]:
 > 

ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php on line 192 #0 /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php(61): Drupal\Component\Utility\Random->sentences()
#1 /var/www/html/drucker/docroot/vendor/drupal/console/src/Command/Create/VocabulariesCommand.php(102): Drupal\Console\Utils\Create\VocabularyData->create(25, 5)
#2 /var/www/html/drucker/docroot/vendor/symfony/console/Command/Command.php(267): Drupal\Console\Command\Create\VocabulariesCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(872): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Drupal\Console\Command\Create\VocabulariesCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/drucker/docroot/vendor/drupal/console-core/src/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/drucker/docroot/vendor/drupal/console/src/Application.php(49): Drupal\Console\Core\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(122): Drupal\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/drucker/docroot/vendor/drupal/console/bin/drupal.php(68): Symfony\Component\Console\Application->run()
#9 phar:///usr/local/bin/drupal/src/Utils/Launcher.php(30): include_once('/var/www/html/d...')
#10 phar:///usr/local/bin/drupal/bin/drupal.php(55): Drupal\Console\Launcher\Utils\Launcher->launch('/var/www/html/d...')
#11 phar:///usr/local/bin/drupal/bin/drupal(3): require('phar:///usr/loc...')
#12 /usr/local/bin/drupal(10): require('phar:///usr/loc...')
#13 {main}
ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in Drupal\Component\Utility\Random->sentences() (line 192 of /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php).

@anavarre I re-read you issue and find out you mentioned 8.4 so I did this:

git clone --branch 8.4.x https://git.drupal.org/project/drupal.git

drupal site:install standard --db-user=root --db-pass=root --force --no-interaction

drupal create:vocabularies

NOTE: My local db credentials for mysql are root/root.

drupal-create-vocabularies

@anavarre can you please:

  • Change directory outside of drupal site root
cd ../
  • Try updating the Launcher
drupal self-update
````

* Check launcher version:

drupal --version


* Change to drupal site root

cd /path/to/drupal


* Rebuilld caches using DrupalConsole

drupal cr all


* Execute `create:vocabularies` command again

drupal create:vocabularies
```

@anavarre When executing drupal --version outside of drupal site root you should see:

drupal-version

So, I've followed your step-by-step but keep running into the same issue. Not sure why.

$ cd ..
$ sudo drupal self-update
[sudo] password for drucker: 
Checking for updates from version: "1.0.0-rc18"
The latest version "1.0.0-rc18" of DrupalConsole Launcher,
was already installed on your system.
$ drupal --version
Drupal Console Launcher version 1.0.0-rc18
Path: /usr/local/bin/drupal

The drupal command should be run from within a Drupal project.
See the documentation page about the Launcher:
https://docs.drupalconsole.com/en/getting/launcher.html

$ cd docroot/
$ drupal cr all

 Rebuilding cache(s), wait a moment please.


 [OK] Done clearing cache(s).                                                                                           


$ drupal create:vocabularies

 // Welcome to the Drupal vocabularies creator

 Enter how many vocabularies would you like to create [25]:
 > 

 Enter the maximum number of words in vocabulary names [5]:
 > 

ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupa
l/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in /var/www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Ra
ndom.php on line 192 #0 /var/www/html/drucker/docroot/vendor/drupal/console/src/Utils/Create/VocabularyData.php(61): Drupal\Component\Utility\Random->
sentences()
#1 /var/www/html/drucker/docroot/vendor/drupal/console/src/Command/Create/VocabulariesCommand.php(102): Drupal\Console\Utils\Create\VocabularyData->cr
eate(25, 5)
#2 /var/www/html/drucker/docroot/vendor/symfony/console/Command/Command.php(267): Drupal\Console\Command\Create\VocabulariesCommand->execute(Object(Sy
mfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(872): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\
Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Drupal\Consol
e\Command\Create\VocabulariesCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/drucker/docroot/vendor/drupal/console-core/src/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Comp
onent\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/drucker/docroot/vendor/drupal/console/src/Application.php(49): Drupal\Console\Core\Application->doRun(Object(Symfony\Component\Consol
e\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/drucker/docroot/vendor/symfony/console/Application.php(122): Drupal\Console\Application->doRun(Object(Symfony\Component\Console\Input
\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/drucker/docroot/vendor/drupal/console/bin/drupal.php(68): Symfony\Component\Console\Application->run()
#9 phar:///usr/local/bin/drupal/src/Utils/Launcher.php(30): include_once('/var/www/html/d...')
#10 phar:///usr/local/bin/drupal/bin/drupal.php(55): Drupal\Console\Launcher\Utils\Launcher->launch('/var/www/html/d...')
#11 phar:///usr/local/bin/drupal/bin/drupal(3): require('phar:///usr/loc...')
#12 /usr/local/bin/drupal(10): require('phar:///usr/loc...')
#13 {main}
ArgumentCountError: Too few arguments to function Drupal\Component\Utility\Random::sentences(), 0 passed in /var/www/html/drucker/docroot/vendor/drupa
l/console/src/Utils/Create/VocabularyData.php on line 61 and at least 1 expected in Drupal\Component\Utility\Random->sentences() (line 192 of /var/
www/html/drucker/docroot/core/lib/Drupal/Component/Utility/Random.php).

Note that due to #3293 I had to install Drupal from 4d80891 which is the latest commit against 8.4.x before Symfony components were upgraded to ~3.2 and made incompatible with Drupal Console.

Found a fix for this. Turns out there is an issue in /src/Utils/Create/VocabularyData.php on line 61. The sentences() call needs arguments (public function sentences($min_word_count, $capitalize = FALSE)), but is blank. Looking at the code:

            $vocabulary = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->create(
                [
                    'name' => $this->getRandom()->sentences(mt_rand(1, $nameWords), true),
                    'description' => $this->getRandom()->sentences(),
                    'vid' => Unicode::strtolower($this->getRandom()->name()),
                    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
                    'weight' => mt_rand(0, 10),
                ]
            );

I would suggest changing line 61 to:
'description' => $this->getRandom()->sentences(mt_rand(1, $nameWords)), or some other upper value thn $nameWords as description can be a bit longer than the actual vocabulary name.

This issue also exists in /src/Utils/Create/TermData.php on line 69. I'd suggest changing it to the following:

            $term = $this->entityTypeManager->getStorage('taxonomy_term')->create(
                [
                    'vid' => $vocabulary,
                    'name' => $this->getRandom()->sentences(mt_rand(1, $nameWords), true),
                    'description' => [
                        'value' => $this->getRandom()->sentences(mt_rand(1, $nameWords)),
                        'format' => 'full_html',
                    ],
                    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
                ]
            );

@brayfe thanks and nice catch, are you interested to send a Pull Request, with the code changes?

Will do!

Was this page helpful?
0 / 5 - 0 ratings