luya\console\Command::selectModule PHP Method

selectModule() public method

Get selection list for console commands with defined options.
Since: 1.0.0-beta4
public selectModule ( array $options = [] ) : string
$options array Define behavior of the module selector prompt, options are name-value pairs. The following options are available: - onlyAdmin: boolean, if enabled all not admin modules will not be included - hideCore: boolean, if enabled all core modules (from luya dev team) will be hidden.
return string The name (ID) of the selected module.
    public function selectModule(array $options = [])
    {
        $modules = [];
        foreach (Yii::$app->getModules() as $id => $object) {
            if (!$object instanceof \luya\base\Module) {
                continue;
            }
            if (isset($options['onlyAdmin'])) {
                if (!$object instanceof AdminModuleInterface) {
                    continue;
                }
            }
            if (isset($options['hideCore'])) {
                if ($object instanceof CoreModuleInterface) {
                    continue;
                }
            }
            $modules[$id] = $id;
        }
        $text = isset($options['text']) ? $options['text'] : 'Please select a module:';
        return $this->select($text, $modules);
    }