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

Breadcrumb

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

function Table::renderCell

Renders table cell with padding.

1 call to Table::renderCell()
Table::renderRow in vendor/symfony/console/Helper/Table.php
Renders table row.

File

vendor/symfony/console/Helper/Table.php, line 549

Class

Table
Provides helpers to display a table.

Namespace

Symfony\Component\Console\Helper

Code

private function renderCell(array $row, int $column, string $cellFormat) : string {
    $cell = $row[$column] ?? '';
    $width = $this->effectiveColumnWidths[$column];
    if ($cell instanceof TableCell && $cell->getColspan() > 1) {
        // add the width of the following columns(numbers of colspan).
        foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) {
            $width += $this->getColumnSeparatorWidth() + $this->effectiveColumnWidths[$nextColumn];
        }
    }
    // str_pad won't work properly with multi-byte strings, we need to fix the padding
    if (false !== ($encoding = mb_detect_encoding($cell, null, true))) {
        $width += \strlen($cell) - mb_strwidth($cell, $encoding);
    }
    $style = $this->getColumnStyle($column);
    if ($cell instanceof TableSeparator) {
        return \sprintf($style->getBorderFormat(), str_repeat($style->getBorderChars()[2], $width));
    }
    $width += Helper::length($cell) - Helper::length(Helper::removeDecoration($this->output
        ->getFormatter(), $cell));
    $content = \sprintf($style->getCellRowContentFormat(), $cell);
    $padType = $style->getPadType();
    if ($cell instanceof TableCell && $cell->getStyle() instanceof TableCellStyle) {
        $isNotStyledByTag = !preg_match('/^<(\\w+|(\\w+=[\\w,]+;?)*)>.+<\\/(\\w+|(\\w+=\\w+;?)*)?>$/', $cell);
        if ($isNotStyledByTag) {
            $cellFormat = $cell->getStyle()
                ->getCellFormat();
            if (!\is_string($cellFormat)) {
                $tag = http_build_query($cell->getStyle()
                    ->getTagOptions(), '', ';');
                $cellFormat = '<' . $tag . '>%s</>';
            }
            if (str_contains($content, '</>')) {
                $content = str_replace('</>', '', $content);
                $width -= 3;
            }
            if (str_contains($content, '<fg=default;bg=default>')) {
                $content = str_replace('<fg=default;bg=default>', '', $content);
                $width -= \strlen('<fg=default;bg=default>');
            }
        }
        $padType = $cell->getStyle()
            ->getPadByAlign();
    }
    return \sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $padType));
}

API Navigation

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