function CommentItem::fieldSettingsForm

Same name and namespace in other branches
  1. 9 core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php \Drupal\comment\Plugin\Field\FieldType\CommentItem::fieldSettingsForm()
  2. 8.9.x core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php \Drupal\comment\Plugin\Field\FieldType\CommentItem::fieldSettingsForm()
  3. 10 core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php \Drupal\comment\Plugin\Field\FieldType\CommentItem::fieldSettingsForm()

Overrides FieldItemBase::fieldSettingsForm

File

core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php, line 104

Class

CommentItem
Plugin implementation of the 'comment' field type.

Namespace

Drupal\comment\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $element = [];
  $settings = $this->getSettings();
  $anonymous_user = new AnonymousUserSession();
  $element['default_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Threading'),
    '#default_value' => $settings['default_mode'],
    '#description' => $this->t('Show comment replies in a threaded list.'),
  ];
  $element['per_page'] = [
    '#type' => 'number',
    '#title' => $this->t('Comments per page'),
    '#default_value' => $settings['per_page'],
    '#required' => TRUE,
    '#min' => 0,
    '#max' => 1000,
    '#description' => $this->t('Enter 0 to show all comments.'),
  ];
  $element['anonymous'] = [
    '#type' => 'select',
    '#title' => $this->t('Anonymous commenting'),
    '#default_value' => $settings['anonymous'],
    '#options' => [
      CommentInterface::ANONYMOUS_MAYNOT_CONTACT => $this->t('Anonymous posters may not enter their contact information'),
      CommentInterface::ANONYMOUS_MAY_CONTACT => $this->t('Anonymous posters may leave their contact information'),
      CommentInterface::ANONYMOUS_MUST_CONTACT => $this->t('Anonymous posters must leave their contact information'),
    ],
    '#access' => $anonymous_user->hasPermission('post comments'),
  ];
  $element['form_location'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Show reply form on the same page as comments'),
    '#default_value' => $settings['form_location'],
  ];
  $element['preview'] = [
    '#type' => 'radios',
    '#title' => $this->t('Preview comment'),
    '#default_value' => $settings['preview'],
    '#options' => [
      DRUPAL_DISABLED => $this->t('Disabled'),
      DRUPAL_OPTIONAL => $this->t('Optional'),
      DRUPAL_REQUIRED => $this->t('Required'),
    ],
  ];
  return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.