public static function BlockUploadBuild::blockUploadRemoveForm in Block Upload 8
Builds form for removing the files with block.
2 calls to BlockUploadBuild::blockUploadRemoveForm()
- BlockUploadForm::buildForm in src/
Form/ BlockUploadForm.php - Form constructor.
- BlockUploadPluploadForm::buildForm in src/
Form/ BlockUploadPluploadForm.php - Form constructor.
File
- src/
BlockUploadBuild.php, line 21
Class
- BlockUploadBuild
- BlockUploadBuild class.
Namespace
Drupal\block_uploadCode
public static function blockUploadRemoveForm($field_limit, $node, $field_name) {
$field_images = $node
->get($field_name);
foreach ($field_images
->getValue() as $field_image) {
$file = File::load($field_image['target_id']);
$uid = $file
->get('uid')->target_id;
$uploader = User::load($uid);
global $base_url;
$url = Url::fromUri($base_url . '/user/' . $uid, []);
$uploader = $uploader ? Link::fromTextAndUrl($uploader
->getDisplayName(), $url) : '';
$options[$field_image['target_id']] = [
[
'data' => [
'#type' => 'item',
'#title' => $uploader ? $uploader
->toString()
->getGeneratedLink() : '',
],
],
[
'data' => [
'#type' => 'item',
'#title' => \Drupal::service('date.formatter')
->format($file
->getCreatedTime()),
],
],
[
'data' => [
'#theme' => 'file_link',
'#file' => (object) $file,
],
'field_type' => $field_limit
->getType(),
],
];
}
$header = [
t('Uploader'),
t('Created time'),
t('File'),
];
$form = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No content available.'),
'#attributes' => [
'class' => [
'delete-files',
],
],
];
return $form;
}