You are here

protected function GenerateTagCommand::interact in Metatag 8

File

src/Command/GenerateTagCommand.php, line 167

Class

GenerateTagCommand
Class GenerateTagCommand.

Namespace

Drupal\metatag\Command

Code

protected function interact(InputInterface $input, OutputInterface $output) {
  $boolean_options = [
    'FALSE',
    'TRUE',
  ];

  // @todo Take this from typed data, so it can be extended?
  $type_options = [
    'integer',
    'string',
    'label',
    'uri',
    'image',
  ];

  // --base_class option.
  // @todo Turn this into a choice() option.
  $base_class = $input
    ->getOption('base_class');
  if (empty($base_class)) {
    $base_class = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.base_class'), 'MetaNameBase');
  }
  $input
    ->setOption('base_class', $base_class);

  // --module option.
  $this
    ->getModuleOption();

  // --name option.
  // @todo Add validation.
  $name = $input
    ->getOption('name');
  if (empty($name)) {
    $name = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.name'));
  }
  $input
    ->setOption('name', $name);

  // --label option.
  $label = $input
    ->getOption('label');
  if (empty($label)) {
    $label = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.label'), $name);
  }
  $input
    ->setOption('label', $label);

  // --description option.
  $description = $input
    ->getOption('description');
  if (empty($description)) {
    $description = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.description'));
  }
  $input
    ->setOption('description', $description);

  // --plugin-id option.
  $plugin_id = $input
    ->getOption('plugin-id');
  if (empty($plugin_id)) {
    $plugin_id = $this
      ->nameToPluginId($name);
    $plugin_id = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.plugin_id'), $plugin_id);
  }
  $input
    ->setOption('plugin-id', $plugin_id);

  // --class-name option.
  $class_name = $input
    ->getOption('class-name');
  if (!$class_name) {
    $class_name = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.class_name'), $this
      ->nameToClassName($name), function ($class_name) {
      return $this->validator
        ->validateClassName($class_name);
    });
    $input
      ->setOption('class-name', $class_name);
  }

  // --group option.
  $group = $input
    ->getOption('group');
  if (empty($group)) {
    $groups = $this
      ->getGroups();
    $group = $this
      ->getIo()
      ->choice($this
      ->trans('commands.generate.metatag.tag.questions.group'), $groups);
  }
  $input
    ->setOption('group', $group);

  // --weight option.
  // @todo Automatically get the next int value based upon the current group.
  $weight = $input
    ->getOption('weight');
  if (is_null($weight)) {
    $weight = $this
      ->getIo()
      ->ask($this
      ->trans('commands.generate.metatag.tag.questions.weight'), 0);
  }
  $input
    ->setOption('weight', $weight);

  // --type option.
  // @todo Turn this into an option.
  $type = $input
    ->getOption('type');
  if (is_null($type)) {
    $type = $this
      ->getIo()
      ->choice($this
      ->trans('commands.generate.metatag.tag.questions.type'), $type_options, 0);
  }
  $input
    ->setOption('type', $type);

  // --secure option.
  // @todo Turn this into an option.
  $secure = $input
    ->getOption('secure');
  if (is_null($secure)) {
    $secure = $this
      ->getIo()
      ->choice($this
      ->trans('commands.generate.metatag.tag.questions.secure'), $boolean_options, 0);
  }
  $input
    ->setOption('secure', $secure);

  // --multiple option.
  $multiple = $input
    ->getOption('multiple');
  if (is_null($multiple)) {
    $multiple = $this
      ->getIo()
      ->choice($this
      ->trans('commands.generate.metatag.tag.questions.multiple'), $boolean_options, 0);
  }
  $input
    ->setOption('multiple', $multiple);
}