You can use IMCE to select a file.
if (\Drupal::moduleHandler()->moduleExists('imce') && \Drupal\imce\Imce::access()) {
$form['values']['image-imce-field'] = [
'#type' => 'textfield',
'#title' => $this->t('Image'),
'#attached' => ['library' => ['imce/drupal.imce.input']],
'#attributes' => ['class' => ['imce-url-input']],
'#default_value' => '',
];
}
Convert file path to FID
public static function getFidFromPath($path) {
$uri = str_replace('/sites/default/files/', 'public://', $path);
$query = \Drupal::entityQuery('file');
$query->condition('uri', $uri);
$query->sort('created', 'DESC');
$fids = $query->execute();
if ($fids) {
$fids = array_values($fids);
return $fids[0] ?? NULL;
}
return NULL;
}
Comments
Education
Pretty company https://order.studentshare.org definitely knows what perfection means. An absolute understanding of quality, customer – oriented management and reasonable prices. They offer all possible services any student might need: technical writing, academic writing, copywriting, website content, science papers, test and even IT projects. Flexible discount system and participation in loyalty programs.
HP printer support assistance; 24/7
Contact us for the HP printer support assistance; 24/7 HP printer customer service help and support available for you. Contact us for immediate assistance! For more info, Please visit at:https://hpprintersupport.us/
Add new comment