Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. QuestionHelper.php

function QuestionHelper::getDefaultAnswer

1 call to QuestionHelper::getDefaultAnswer()
QuestionHelper::ask in vendor/symfony/console/Helper/QuestionHelper.php
Asks a question to the user.

File

vendor/symfony/console/Helper/QuestionHelper.php, line 157

Class

QuestionHelper
The QuestionHelper class provides helpers to interact with the user.

Namespace

Symfony\Component\Console\Helper

Code

private function getDefaultAnswer(Question $question) : mixed {
    $default = $question->getDefault();
    if (null === $default) {
        return $default;
    }
    if ($validator = $question->getValidator()) {
        return \call_user_func($validator, $default);
    }
    elseif ($question instanceof ChoiceQuestion) {
        $choices = $question->getChoices();
        if (!$question->isMultiselect()) {
            return $choices[$default] ?? $default;
        }
        $default = explode(',', $default);
        foreach ($default as $k => $v) {
            $v = $question->isTrimmable() ? trim($v) : $v;
            $default[$k] = $choices[$v] ?? $v;
        }
    }
    return $default;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal