public function FileController::inlineEdit in File Entity (fieldable files) 8.2
Return an Ajax dialog command for editing a file inline.
Parameters
\Drupal\file\FileInterface $file: The file being edited.
Return value
\Drupal\Core\Ajax\AjaxResponse An Ajax response with a command for opening or closing the a dialog containing the edit form.
1 string reference to 'FileController::inlineEdit'
File
- src/
Controller/ FileController.php, line 120
Class
- FileController
- Class FileController
Namespace
Drupal\file_entity\ControllerCode
public function inlineEdit(FileInterface $file) {
// Build the file edit form.
$form_object = $this
->entityTypeManager()
->getFormObject('file', 'inline_edit');
$form_object
->setEntity($file);
$form_state = (new FormState())
->setFormObject($form_object)
->disableRedirect();
// Building the form also submits.
$form = $this
->formBuilder()
->buildForm($form_object, $form_state);
$dialog_selector = '#file-entity-inline-edit-' . $file
->id();
// Return a response, depending on whether it's successfully submitted.
if (!$form_state
->isExecuted()) {
// Return the form as a modal dialog.
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$title = $this
->t('Edit file @file', [
'@file' => $file
->label(),
]);
$response = AjaxResponse::create()
->addCommand(new OpenDialogCommand($dialog_selector, $title, $form, [
'width' => 800,
]));
return $response;
}
else {
// Return command for closing the modal.
return AjaxResponse::create()
->addCommand(new CloseDialogCommand($dialog_selector));
}
}