5 * Contains \Drupal\Console\Generator\PluginBlockGenerator.
8 namespace Drupal\Console\Generator;
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
13 class PluginBlockGenerator extends Generator
18 protected $extensionManager;
21 * PermissionGenerator constructor.
23 * @param Manager $extensionManager
25 public function __construct(
26 Manager $extensionManager
28 $this->extensionManager = $extensionManager;
32 * Generator Plugin Block.
40 public function generate($module, $class_name, $label, $plugin_id, $services, $inputs)
42 // Consider the type when determining a default value. Figure out what
43 // the code looks like for the default value tht we need to generate.
44 foreach ($inputs as &$input) {
45 $default_code = '$this->t(\'\')';
46 if ($input['default_value'] == '') {
47 switch ($input['type']) {
57 $default_code = 'array()';
60 } elseif (substr($input['default_value'], 0, 1) == '$') {
61 // If they want to put in code, let them, they're programmers.
62 $default_code = $input['default_value'];
63 } elseif (is_numeric($input['default_value'])) {
64 $default_code = $input['default_value'];
65 } elseif (preg_match('/^(true|false)$/i', $input['default_value'])) {
67 $default_code = strtoupper($input['default_value']);
69 $default_code = '$this->t(\'' . $input['default_value'] . '\')';
71 $input['default_code'] = $default_code;
76 'class_name' => $class_name,
78 'plugin_id' => $plugin_id,
79 'services' => $services,
84 'module/src/Plugin/Block/block.php.twig',
85 $this->extensionManager->getPluginPath($module, 'Block').'/'.$class_name.'.php',