protected function FileBrowserWidget::getPersistentData in Entity Browser 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/FileBrowserWidget.php \Drupal\entity_browser\Plugin\Field\FieldWidget\FileBrowserWidget::getPersistentData()
Gets data that should persist across Entity Browser renders.
Return value
array Data that should persist after the Entity Browser is rendered.
Overrides EntityReferenceBrowserWidget::getPersistentData
File
- src/
Plugin/ Field/ FieldWidget/ FileBrowserWidget.php, line 524
Class
- FileBrowserWidget
- Entity browser file widget.
Namespace
Drupal\entity_browser\Plugin\Field\FieldWidgetCode
protected function getPersistentData() {
$data = parent::getPersistentData();
$settings = $this->fieldDefinition
->getSettings();
// Add validators based on our current settings.
$data['validators']['file'] = [
'validators' => $this
->getFileValidators(),
];
// Provide context for widgets to enhance their configuration.
$data['widget_context']['upload_location'] = $settings['uri_scheme'] . '://' . $settings['file_directory'];
$data['widget_context']['upload_validators'] = $this
->getFileValidators(TRUE);
// Assemble valid mime types for filtering. This is required if we want to
// contextually filter allowed extensions in views, as views arguments can
// only filter on exact values. Otherwise we would pass %png or use REGEXP.
$mimetypes = [];
foreach (explode(' ', $settings['file_extensions']) as $extension) {
if ($guess = $this->mimeTypeGuesser
->guess('file.' . $extension)) {
$mimetypes[] = $guess;
}
}
$data['widget_context']['target_file_mimetypes'] = $mimetypes;
return $data;
}