public function AnonymousPublishingClAdminUnverified::buildForm in Anonymous Publishing 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
anonymous_publishing_cl/ src/ Form/ AnonymousPublishingClAdminUnverified.php, line 48
Class
Namespace
Drupal\anonymous_publishing_cl\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Build an 'Update options' form.
$form['options'] = array(
'#type' => 'details',
'#title' => $this
->t('Update options'),
'#open' => TRUE,
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$options = array(
'ban' => $this
->t("Delete item and ban it's IP"),
);
$form['options']['operation'] = array(
'#type' => 'select',
'#title' => $this
->t('Action'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'publish',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Update'),
);
$form['apu_info'] = [
'#markup' => t("<p>The following table shows the IP-addresses, verification email address used, date posted and title of still <em>unverified</em> anonymous posts. To delete the contents and ban the IP-address by moving to Drupal's <code>{blocked_ips}</code> table, check the box in the corresponding lines and execute the “Delete item and ban it's IP” action.</p><p>As an alternative to the Drupal <code>{blocked_ips}</code> table you may instead deny access to unwanted IP-addresses using the appropriate command in the web server access file.</p>"),
];
$header = array(
'title' => array(
'data' => $this
->t('Title'),
),
'type' => array(
'data' => $this
->t('Type'),
),
'ip' => array(
'data' => $this
->t('IP-address'),
),
'email' => array(
'data' => $this
->t('Verification email'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
),
'when' => array(
'data' => $this
->t('When'),
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
'sort' => 'desc',
),
);
$options = array();
$hidden_values = array();
// Fetch all unverified posts.
$rows = $this
->getAllUnverifiedContents($header);
foreach ($rows as $row) {
// Default values:
$url = NULL;
$type = $this
->t('undefined');
$titlefield = '';
$datefield = '';
// Retrieve the title and date of the comment or node depending.
if ($row->cid) {
$comment = Comment::load($row->cid);
$type = $this
->t('comment');
if ($comment) {
$datefield = $comment
->getCreatedTime();
$titlefield = !empty($comment
->getSubject()) ? $comment
->getSubject() : '- empty -';
$url = $comment
->permalink();
}
else {
$titlefield = $this
->t('-deleted-');
$datefield = '';
$url = NULL;
}
}
else {
if ($row->nid) {
$type = $this
->t('node');
$node = Node::load($row->nid);
if ($node) {
$datefield = $node
->getCreatedTime();
$titlefield = $node
->getTitle();
$url = $node
->toUrl();
}
else {
$titlefield = $this
->t('-deleted-');
$datefield = '';
$url = NULL;
}
}
}
$datefield = !empty($datefield) ? \Drupal::service("date.formatter")
->formatInterval(\Drupal::time()
->getRequestTime() - $datefield, 1) . ' ' . t('ago') : '-NULL-';
if ($url) {
$datatitle = array(
'#type' => 'link',
'#title' => $titlefield,
'#url' => $url,
);
}
else {
$datatitle = array(
'#markup' => $titlefield,
);
}
$options[$row->apid] = array(
'title' => array(
'data' => $datatitle,
),
'type' => array(
'data' => array(
'#markup' => $type,
),
),
'ip' => array(
'data' => array(
'#markup' => $row->ip,
),
),
'email' => array(
'data' => array(
'#markup' => $row->email,
),
),
'when' => array(
'data' => array(
'#markup' => $datefield,
),
),
);
$hidden_values[$row->apid] = array(
'nid' => $row->nid,
'cid' => $row->cid,
'ip' => $row->ip,
);
}
$form['hidden_values'] = array(
'#type' => 'hidden',
'#value' => serialize($hidden_values),
);
$form['items'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => $this
->t('There is no unverified content.'),
);
$form['pager'] = array(
'#type' => 'pager',
);
return $form;
}