X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FEntityCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FEntityCommand.php;h=d5869edc7b75b70341b4dde771dc224d6332ffc9;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Generate/EntityCommand.php b/vendor/drupal/console/src/Command/Generate/EntityCommand.php new file mode 100644 index 000000000..d5869edc7 --- /dev/null +++ b/vendor/drupal/console/src/Command/Generate/EntityCommand.php @@ -0,0 +1,176 @@ +entityType = $entityType; + } + + /** + * @param $commandName + */ + protected function setCommandName($commandName) + { + $this->commandName = $commandName; + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $commandKey = str_replace(':', '.', $this->commandName); + + $this + ->setName($this->commandName) + ->setDescription( + sprintf( + $this->trans('commands.'.$commandKey.'.description'), + $this->entityType + ) + ) + ->setHelp( + sprintf( + $this->trans('commands.'.$commandKey.'.help'), + $this->commandName, + $this->entityType + ) + ) + ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) + ->addOption( + 'entity-class', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.entity-class') + ) + ->addOption( + 'entity-name', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.entity-name') + ) + ->addOption( + 'base-path', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.' . $commandKey . '.options.base-path') + ) + ->addOption( + 'label', + null, + InputOption::VALUE_REQUIRED, + $this->trans('commands.'.$commandKey.'.options.label') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + // Operations defined in EntityConfigCommand and EntityContentCommand. + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $commandKey = str_replace(':', '.', $this->commandName); + $utils = $this->stringConverter; + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // --entity-class option + $entityClass = $input->getOption('entity-class'); + if (!$entityClass) { + $entityClass = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.entity-class'), + 'DefaultEntity', + function ($entityClass) { + return $this->validator->validateSpaces($entityClass); + } + ); + + $input->setOption('entity-class', $entityClass); + } + + // --entity-name option + $entityName = $input->getOption('entity-name'); + if (!$entityName) { + $entityName = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.entity-name'), + $utils->camelCaseToMachineName($entityClass), + function ($entityName) { + return $this->validator->validateMachineName($entityName); + } + ); + $input->setOption('entity-name', $entityName); + } + + // --label option + $label = $input->getOption('label'); + if (!$label) { + $label = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.label'), + $utils->camelCaseToHuman($entityClass) + ); + $input->setOption('label', $label); + } + + // --base-path option + $base_path = $input->getOption('base-path'); + if (!$base_path) { + $base_path = $this->getDefaultBasePath(); + } + $base_path = $io->ask( + $this->trans('commands.'.$commandKey.'.questions.base-path'), + $base_path + ); + if (substr($base_path, 0, 1) !== '/') { + // Base path must start with a leading '/'. + $base_path = '/' . $base_path; + } + $input->setOption('base-path', $base_path); + } + + /** + * Gets default base path. + * + * @return string + * Default base path. + */ + protected function getDefaultBasePath() + { + return '/admin/structure'; + } +}