class DescriptionForm in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/Form/DescriptionForm.php \Drupal\filebrowser\Form\DescriptionForm
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\filebrowser\Form\DescriptionForm
Expanded class hierarchy of DescriptionForm
File
- src/
Form/ DescriptionForm.php, line 9
Namespace
Drupal\filebrowser\FormView source
class DescriptionForm extends FormBase {
/**
* @var array
* Array of ids of the entities to be edited
*/
protected $e_ids;
/**
* @var array
* Array of entities to be edited.
*/
protected $entities;
protected $nid;
protected $queryFid;
/**
* @var \Drupal\filebrowser\Services\Common
*/
protected $common;
/**
* @var \Drupal\filebrowser\Services\FilebrowserStorage
*/
protected $storage;
/**
* @inheritdoc
*/
public function getFormId() {
return 'filebrowser_form_edit_file_description';
}
/**
* @param int $nid
* @param int $query_fid
* @param array $fids
* @param $form
* @param $form_state
* @param $ajax
* @return array
*/
public function buildForm(array $form, FormStateInterface $form_state, $nid = null, $query_fid = null, $fids = null, $ajax = null) {
$fid_array = explode(',', $fids);
$this->nid = $nid;
$this->queryFid = $query_fid;
$this->common = \Drupal::service('filebrowser.common');
// we need to load the fileData to retrieve the filename
$this->storage = \Drupal::service('filebrowser.storage');
$file_data = $this->storage
->nodeContentLoadMultiple($fid_array);
// Load the description-metadata
$ids = \Drupal::entityQuery('filebrowser_metadata_entity')
->condition('fid', $fid_array, "IN")
->condition('name', 'description')
->execute();
$this->entities = \Drupal::entityTypeManager()
->getStorage('filebrowser_metadata_entity')
->loadMultiple($ids);
$descriptions = [];
foreach ($this->entities as $entity) {
$descriptions[$entity->fid->value] = unserialize($entity->content->value)['title'];
}
// if this form is opened by ajax add a close link.
if ($ajax) {
$form['#attributes'] = [
'class' => [
'form-in-slide-down',
],
];
$form['close'] = $this->common
->closeButtonMarkup();
}
$form['items'] = [
'#title' => $this
->t('Edit description'),
'#type' => 'fieldset',
'#tree' => true,
];
foreach ($descriptions as $key => $description) {
$properties = unserialize($file_data[$key]['file_data']);
//debug($properties);
$form['items'][$key] = [
'#type' => 'textarea',
'#title' => $properties->filename,
'#rows' => 3,
'#default_value' => $description,
];
}
$form['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}
/**
* @inheritdoc
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var FilebrowserMetadataEntity $entity */
$values = $form_state
->getValue('items');
foreach ($this->entities as $entity) {
$content = unserialize($entity->content->value);
$fid = $entity->fid->value;
$content['title'] = $values[$fid];
$entity
->setContent(serialize($content));
$entity
->save();
}
if ($this->nid) {
$route = $this->common
->redirectRoute($this->queryFid, $this->nid);
$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 | |
DescriptionForm:: |
protected | property | ||
DescriptionForm:: |
protected | property | Array of entities to be edited. | |
DescriptionForm:: |
protected | property | Array of ids of the entities to be edited | |
DescriptionForm:: |
protected | property | ||
DescriptionForm:: |
protected | property | ||
DescriptionForm:: |
protected | property | ||
DescriptionForm:: |
public | function |
_state Overrides FormInterface:: |
|
DescriptionForm:: |
public | function |
@inheritdoc Overrides FormInterface:: |
|
DescriptionForm:: |
public | function |
@inheritdoc Overrides FormInterface:: |
|
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
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. |