Created
October 19, 2018 17:36
-
-
Save DanLaufer/88311a03808e0dfa723f75dd43e8c2df to your computer and use it in GitHub Desktop.
Drupal 8 - Act on files in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load file from id | |
$file_entity = \Drupal::entityTypeManager()->getStorage('file')->load($target_id); | |
//Get Uri/Url of file | |
//in preprocess field | |
$svg_uri = $vars['items']['0']['content']['#file']->getFileUri(); | |
//in preprocess node | |
$svg_uri = $node->field_svg_image->entity->get('uri')->getValue(); | |
$img_path = file_create_url($svg_uri); | |
//in preprocess paragraph | |
$temp_file = $current_hero->field_gated_content->entity; | |
$gated_file_url = \Drupal\Core\Url::fromUri(file_create_url($temp_file->getFileUri()))->toString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment