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

Breadcrumb

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

function SymfonyStyle::definitionList

Formats a list of key/value horizontally.

Each row can be one of:

  • 'A title'
  • ['key' => 'value']
  • new TableSeparator()

File

vendor/symfony/console/Style/SymfonyStyle.php, line 186

Class

SymfonyStyle
Output decorator helpers for the Symfony Style Guide.

Namespace

Symfony\Component\Console\Style

Code

public function definitionList(string|array|TableSeparator ...$list) : void {
    $headers = [];
    $row = [];
    foreach ($list as $value) {
        if ($value instanceof TableSeparator) {
            $headers[] = $value;
            $row[] = $value;
            continue;
        }
        if (\is_string($value)) {
            $headers[] = new TableCell($value, [
                'colspan' => 2,
            ]);
            $row[] = null;
            continue;
        }
        if (!\is_array($value)) {
            throw new InvalidArgumentException('Value should be an array, string, or an instance of TableSeparator.');
        }
        $headers[] = key($value);
        $row[] = current($value);
    }
    $this->horizontalTable($headers, [
        $row,
    ]);
}

API Navigation

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