You are here

protected function TagSetForm::buildRow in Extensible BBCode 8.3

Same name and namespace in other branches
  1. 4.0.x src/Form/TagSetForm.php \Drupal\xbbcode\Form\TagSetForm::buildRow()

Build a table row for a single plugin.

Parameters

\Drupal\xbbcode\Plugin\TagPluginInterface $plugin: The plugin instance.

bool $enabled: Whether or not the plugin is currently enabled.

Return value

array A form array to put into the parent table.

1 call to TagSetForm::buildRow()
TagSetForm::form in src/Form/TagSetForm.php
Gets the actual form array to be built.

File

src/Form/TagSetForm.php, line 201

Class

TagSetForm
Base form for tag sets.

Namespace

Drupal\xbbcode\Form

Code

protected function buildRow(TagPluginInterface $plugin, $enabled) : array {
  $row = [
    '#enabled' => $enabled,
    '#default_name' => $plugin
      ->getDefaultName(),
  ];
  $path = $enabled ? 'enabled:' . $plugin
    ->getName() : 'available:' . $plugin
    ->getPluginId();
  $row['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Tag name'),
    '#title_display' => 'invisible',
    '#required' => TRUE,
    '#size' => 8,
    '#field_prefix' => '[',
    '#field_suffix' => ']',
    '#default_value' => $plugin
      ->getName(),
    '#pattern' => '[a-z0-9_-]+',
    '#attributes' => [
      'default' => $plugin
        ->getDefaultName(),
    ],
    '#states' => [
      'enabled' => [
        ':input[name="_tags[' . $path . ']"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $row['label'] = [
    '#type' => 'inline_template',
    '#template' => '<strong>{{ plugin.label }}</strong><br />{{ plugin.description}}',
    '#context' => [
      'plugin' => $plugin,
    ],
  ];
  $row['id'] = [
    '#type' => 'value',
    '#value' => $plugin
      ->getPluginId(),
  ];
  return $row;
}