public function WordfilterConfigurationForm::wordfilterItemSettings in Wordfilter 8.2
Form builder for settings of a given Filtering item.
See also
::buildForm().
2 calls to WordfilterConfigurationForm::wordfilterItemSettings()
- WordfilterConfigurationForm::buildForm in src/
Form/ WordfilterConfigurationForm.php - Form constructor.
- WordfilterConfigurationForm::wordfilterNewItemSettings in src/
Form/ WordfilterConfigurationForm.php - Form builder for settings of a new Filtering item.
File
- src/
Form/ WordfilterConfigurationForm.php, line 197
Class
- WordfilterConfigurationForm
- Class WordfilterConfigurationForm.
Namespace
Drupal\wordfilter\FormCode
public function wordfilterItemSettings(array &$form, FormStateInterface $form_state, WordfilterItem $item) {
$count = count($form_state
->getValue('items', []));
if ($count === 0) {
$count = $form_state
->getValue('wordfilter_item_count', 0);
$count++;
}
$form_state
->setValue('wordfilter_item_count', $count);
$delta = $item
->getDelta();
$id = Html::getUniqueId('edit-items-' . $delta);
$settings = [
'#type' => 'fieldset',
'#title' => t('Item #@num', [
'@num' => $count,
]),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => $delta,
'#attributes' => [
'id' => $id,
],
];
$settings['delta'] = [
'#type' => 'value',
'#value' => $delta,
'#weight' => 10,
];
$settings['substitute'] = [
'#type' => 'textfield',
'#title' => $this
->t('Substitution text'),
'#default_value' => $item
->getSubstitute(),
'#description' => $this
->t('Any filtered word will be replaced by this substitution text (optional).'),
'#required' => FALSE,
'#weight' => 20,
];
$settings['filter_words'] = [
'#type' => 'textfield',
'#title' => $this
->t('Words to filter'),
'#default_value' => implode(', ', $item
->getFilterWords()),
'#description' => \Drupal::theme()
->render('item_list', [
'items' => [
$this
->t('Enter a <strong>comma-separated</strong> list of filter words.'),
$this
->t('Example: <em>Somebadword, Another, [placeholder]</em>.'),
],
]),
'#required' => FALSE,
'#weight' => 30,
];
$settings['remove'] = [
'#type' => 'submit',
'#name' => 'remove_item_' . $delta,
'#value' => t('Remove this item'),
'#ajax' => [
'callback' => [
$this,
'removeWordfilterItemAjax',
],
'wrapper' => $id,
'effect' => 'fade',
'progress' => [
'type' => 'throbber',
'message' => t('Removing...'),
],
],
'#submit' => [
'::removeWordfilterItemAjax',
],
'#weight' => 40,
];
$form['items'][$delta] = $settings;
return $form['items'][$delta];
}