public function RestrictWordsController::content in Restrict Abusive Words 8
File
- src/
Controller/ RestrictWordsController.php, line 18 - Contains \Drupal\restrict_abusive_words\Controller\RestrictWordsController.
Class
Namespace
Drupal\restrict_abusive_words\ControllerCode
public function content() {
$rows = array();
$header = array(
array(
'data' => $this
->t('Id'),
'field' => 'raw.id',
),
array(
'data' => $this
->t('Word'),
'field' => 'raw.words',
'sort' => 'desc',
),
array(
'data' => $this
->t('Edit'),
),
array(
'data' => $this
->t('Delete'),
),
);
$conn = Database::getConnection();
$query = $conn
->select('restrict_abusive_words', 'raw')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->fields('raw');
$result = $query
->limit(10)
->orderByHeader($header)
->execute();
foreach ($result as $word) {
$editUrl = Url::fromRoute('restrict_abusive_words.edit_words', array(
'wid' => $word->id,
));
$deleteUrl = Url::fromRoute('restrict_abusive_words.delete_words', array(
'wid' => $word->id,
));
$rows[] = array(
'data' => array(
array(
'data' => $word->id,
),
array(
'data' => $word->words,
),
array(
'data' => \Drupal::l(t('Edit word'), $editUrl),
),
array(
'data' => \Drupal::l(t('Delete word'), $deleteUrl),
),
),
);
}
$build['result'] = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this
->t('No words added.'),
);
$build['pager'] = array(
'#type' => 'pager',
);
return $build;
}