public function SocialCommentAdminOverview::buildForm in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 8.3 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 8.4 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 8.5 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 8.6 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 8.7 modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 10.3.x modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 10.0.x modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 10.1.x modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
- 10.2.x modules/social_features/social_comment/src/Form/SocialCommentAdminOverview.php \Drupal\social_comment\Form\SocialCommentAdminOverview::buildForm()
Form constructor for the comment overview administration form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
string $type: The type of the overview form ('approval' or 'new').
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
social_features/ social_comment/ src/ Form/ SocialCommentAdminOverview.php, line 120
Class
- SocialCommentAdminOverview
- Provides the comments overview administration form.
Namespace
Drupal\social_comment\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $type = 'new') {
// Build an 'Update options' form.
$form['options'] = [
'#type' => 'details',
'#title' => $this
->t('Update options'),
'#open' => TRUE,
'#attributes' => [
'class' => [
'container-inline',
],
],
];
if ($type == 'approval') {
$options['publish'] = $this
->t('Publish the selected comments');
}
else {
$options['unpublish'] = $this
->t('Unpublish the selected comments');
}
$options['delete'] = $this
->t('Delete the selected comments');
$form['options']['operation'] = [
'#type' => 'select',
'#title' => $this
->t('Action'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'publish',
];
$form['options']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Update'),
];
// Load the comments that need to be displayed.
$status = $type == 'approval' ? CommentInterface::NOT_PUBLISHED : CommentInterface::PUBLISHED;
$header = [
'author' => [
'data' => $this
->t('Author'),
'specifier' => 'name',
'class' => [
RESPONSIVE_PRIORITY_MEDIUM,
],
],
'comment' => [
'data' => $this
->t('Comment'),
'specifier' => 'comment_body',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
'changed' => [
'data' => $this
->t('Updated'),
'specifier' => 'changed',
'sort' => 'desc',
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
],
'operations' => $this
->t('Operations'),
];
$cids = $this->commentStorage
->getQuery()
->condition('status', $status)
->tableSort($header)
->pager(50)
->execute();
/* @var $comments \Drupal\comment\CommentInterface[] */
$comments = $this->commentStorage
->loadMultiple($cids);
// Build a table listing the appropriate comments.
$options = [];
$destination = $this
->getDestinationArray();
foreach ($comments as $comment) {
// Get a render array for the comment body field. We'll render it in the
// table.
$comment_body = $comment->field_comment_body
->view('full');
$options[$comment
->id()] = [
'title' => [
'data' => [
'#title' => $comment
->getSubject() ?: $comment
->id(),
],
],
'author' => [
'data' => [
'#theme' => 'username',
'#account' => $comment
->getOwner(),
],
],
'comment' => [
'data' => [
'#markup' => $this->renderer
->renderRoot($comment_body),
],
],
'changed' => $this->dateFormatter
->format($comment
->getChangedTimeAcrossTranslations(), 'short'),
];
// Create a list of operations.
$comment_uri_options = $comment
->toUrl()
->getOptions() + [
'query' => $destination,
];
$links['view'] = [
'title' => $this
->t('View'),
'url' => $comment
->toUrl(),
];
$links['edit'] = [
'title' => $this
->t('Edit'),
'url' => $comment
->toUrl('edit-form', $comment_uri_options),
];
$links['delete'] = [
'title' => $this
->t('Delete'),
'url' => $comment
->toUrl('delete-form', $comment_uri_options),
];
// Add a 'Translate' operations link if the comment is translatable.
if ($this->moduleHandler
->moduleExists('content_translation') && $comment
->getCommentedEntity() instanceof ContentEntityInterface && $this->moduleHandler
->invoke('content_translation', 'translate_access', [
$comment,
])
->isAllowed()) {
$links['translate'] = [
'title' => $this
->t('Translate'),
'url' => $comment
->toUrl('drupal:content-translation-overview', $comment_uri_options),
];
}
$options[$comment
->id()]['operations']['data'] = [
'#type' => 'operations',
'#links' => $links,
];
}
$form['comments'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => $this
->t('No comments available.'),
];
$form['pager'] = [
'#type' => 'pager',
];
return $form;
}