commands-1.x-dev/src/Plugin/Command/EchoCommand.php
src/Plugin/Command/EchoCommand.php
<?php
namespace Drupal\commands\Plugin\Command;
use Drupal\commands\CommandPluginBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Example plugin for Command Types. Echos a string.
*
* @Command(
* id = "echo",
* label = @Translation("Echo a string"),
* description = @Translation("Echos an arbitrary string."),
* command = "echo [message]"
* )
*/
class EchoCommand extends CommandPluginBase {
/**
* Show a form on the "Run command" form.
* @return void
*/
public function form($form, FormStateInterface $form_state) {
$form['parameters']['message'] = [
'#type' => 'textfield',
'#title' => t('Message'),
'#default_value' => t('Hello, :user!', [
':user' => \Drupal::currentUser()->getAccountName()
]),
'#required' => TRUE,
'#description'=> t('Enter a string to echo.'),
];
return $form;
}
}
