public function DescriptionForm::buildForm in Filebrowser 3.x
Same name and namespace in other branches
- 8.2 src/Form/DescriptionForm.php \Drupal\filebrowser\Form\DescriptionForm::buildForm()
_state
Parameters
int $nid:
int $query_fid:
array $fids:
$form:
$ajax:
Return value
array
Overrides FormInterface::buildForm
File
- src/
Form/ DescriptionForm.php, line 51
Class
Namespace
Drupal\filebrowser\FormCode
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;
}