class FolderForm in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/Form/FolderForm.php \Drupal\filebrowser\Form\FolderForm
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\filebrowser\Form\FolderForm
Expanded class hierarchy of FolderForm
File
- src/
Form/ FolderForm.php, line 11
Namespace
Drupal\filebrowser\FormView source
class FolderForm extends FormBase {
/**
* @var int
* If we create a folder in a sub folder this is the fid
* of the subfolder. If we want to redirect to the node page we can use
* the url query /node/{nid}?fid=$relativeFid
*/
protected $relativeFid;
/**
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* @var string
*/
protected $relativeRoot;
/**
* @var \Drupal\filebrowser\Services\Common
*/
protected $common;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'create_folder_form';
}
/**
* {@inheritdoc}
* @var array $list
*/
public function buildForm(array $form, FormStateInterface $form_state, $nid = null, $relative_fid = null, $fids = null, $ajax = null) {
$this->common = \Drupal::service('filebrowser.common');
$this->relativeRoot = $this->common
->relativePath($relative_fid);
$this->node = Node::load($nid);
$this->relativeFid = $relative_fid;
// 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['#tree'] = true;
$form['folder_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Folder Name'),
'#size' => 40,
'#description' => $this
->t('This folder will be created within the current directory.'),
'#required' => true,
];
$form['create'] = [
'#type' => 'submit',
'#value' => $this
->t('Create'),
'#name' => 'create',
];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['#attached']['library'][] = 'filebrowser/filebrowser-styles';
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$folder_uri = $this->node->filebrowser->folderPath . $this->relativeRoot . '/' . $form_state
->getValue('folder_name');
$success = \Drupal::service('file_system')
->prepareDirectory($folder_uri, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
if (!$success) {
\Drupal::messenger()
->addError($this
->t('Unable to create this folder, do you have filesystem right to do that ?'));
}
else {
Cache::invalidateTags([
'filebrowser:node:' . $this->node
->id(),
]);
}
$route = $this->common
->redirectRoute($this->relativeFid, $this->node
->id());
$form_state
->setRedirect($route['name'], $route['node'], $route['query']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FolderForm:: |
protected | property | ||
FolderForm:: |
protected | property | ||
FolderForm:: |
protected | property | If we create a folder in a sub folder this is the fid of the subfolder. If we want to redirect to the node page we can use the url query /node/{nid}?fid=$relativeFid | |
FolderForm:: |
protected | property | ||
FolderForm:: |
public | function |
Overrides FormInterface:: |
|
FolderForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
FolderForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
FolderForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
105 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |