DevelTokenCommand.php

Same filename in this branch
  1. 5.x src/Drush/Commands/DevelTokenCommand.php

Namespace

Drupal\devel\Command

File

src/Command/DevelTokenCommand.php

View source
<?php

declare (strict_types=1);
namespace Drupal\devel\Command;

use Drupal\Core\Utility\Token;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Lists the available tokens.
 */
class DevelTokenCommand {
  use FormatTrait;
  public const NAME = 'devel:token';
  public function __construct(protected readonly Token $token) {
  }
  
  /**
   * Lists the available tokens.
   */
  public function __invoke(OutputInterface $output, #[Option('The output format: table, json or yaml.')] string $format = 'table') : int {
    $rows = [];
    foreach ($this->token
      ->getInfo()['tokens'] as $group => $tokens) {
      foreach ($tokens as $key => $token) {
        $rows[] = [
          'group' => $group,
          'token' => $key,
          'name' => (string) $token['name'],
        ];
      }
    }
    $this->writeRows($output, $rows, [
      'group' => 'Group',
      'token' => 'Token',
      'name' => 'Name',
    ], $format);
    return Command::SUCCESS;
  }

}

Classes

Title Deprecated Summary
DevelTokenCommand Lists the available tokens.