public function RenameForm::buildForm in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/Form/RenameForm.php \Drupal\filebrowser\Form\RenameForm::buildForm()
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/ RenameForm.php, line 72
Class
Namespace
Drupal\filebrowser\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $nid = null, $query_fid = null, $fids_str = null, $ajax = null) {
/** @var \Drupal\filebrowser\Services\FilebrowserValidator $validate */
$this->common = \Drupal::service('filebrowser.common');
$this->storage = \Drupal::service('filebrowser.storage');
$this->node = Node::load($nid);
$this->oldNames = [];
$this->fids = explode(',', $fids_str);
$this->queryFid = $query_fid;
$this->contents = $this->storage
->nodeContentLoadMultiple($this->fids);
$this->relativeRoot = reset($this->contents)['root'];
$this->route = $this->common
->redirectRoute($this->queryFid, $this->node
->id());
$form['#tree'] = true;
// If this form is to be presented in a slide-down window we
// will set the attributes and at a close-window link
if ($ajax) {
$form['#attributes'] = [
'class' => [
'form-in-slide-down',
],
];
$form['close-window'] = $this->common
->closeButtonMarkup();
}
$form['help'] = [
'#markup' => $this
->t('Enter new filename <strong>without</strong> extension.'),
];
foreach ($this->contents as $key => $row) {
$this->contents[$key]['data_array'] = $data = unserialize($row['file_data']);
$filename = \Drupal::service('file_system')
->basename($data->uri);
$name = pathinfo($filename, PATHINFO_FILENAME);
$this->oldNames[$key] = $name;
$form['new_name'][$key] = [
'#type' => 'textfield',
'#title' => $filename,
'#default_value' => $name,
];
}
$form = parent::buildForm($form, $form_state);
$form['actions']['cancel']['#attributes']['class'][] = 'button btn btn-default';
return $form;
}