public function DownloadCountResetForm::buildForm in Download Count 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 ConfirmFormBase::buildForm
File
- src/
Form/ DownloadCountResetForm.php, line 51
Class
- DownloadCountResetForm
- Implements the reset form controller.
Namespace
Drupal\download_count\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $download_count_entry = NULL) {
if ($download_count_entry != NULL) {
$connection = Database::getConnection();
$query = $connection
->select('download_count', 'dc');
$query
->join('file_managed', 'f', 'dc.fid = f.fid');
$query
->fields('dc', [
'dcid',
'fid',
'uid',
'type',
'id',
'ip_address',
'referrer',
'timestamp',
]);
$query
->fields('f', [
'filename',
'uri',
'filemime',
'filesize',
]);
$query
->condition('dc.dcid', $download_count_entry);
$this->dcEntry = $query
->execute()
->fetchObject();
}
else {
$this->dcEntry = 'all';
}
if ($this->dcEntry != 'all') {
$form['dcid'] = [
'#type' => 'value',
'#value' => $this->dcEntry->dcid,
];
$form['filename'] = [
'#type' => 'value',
'#value' => Html::escape($this->dcEntry->filename),
];
$form['fid'] = [
'#type' => 'value',
'#value' => $this->dcEntry->fid,
];
$form['type'] = [
'#type' => 'value',
'#value' => Html::escape($this->dcEntry->type),
];
$form['id'] = [
'#type' => 'value',
'#value' => $this->dcEntry->id,
];
$this->confirm = TRUE;
$this->question = TRUE;
return parent::buildForm($form, $form_state);
}
else {
$form['dcid'] = [
'#type' => 'value',
'#value' => 'all',
];
$this->confirm = TRUE;
$this->question = TRUE;
return parent::buildForm($form, $form_state);
}
}