I want to execute a View and export the JSON file to the files directory. I am using Views Data Export and VDE drush add-on modules. My view has a file/PDF field and I want to provide a direct link to the PDF file. So I added a Views relation for the field and a file URI formatter field. When I go to see the output the View creates at the Path. The URL is an absolute link directly to the PDF file. The URL includes the domain name when viewing it on development or production instances. And this is what I want. This is the correct URL path in the JSON:
href=\u0022http:\/\/mysite.com\/files\/Allergens.pdf
But when I use this Drush command below provided by views_data_export
or vde_drush
drush vde myview myviewid myfile.json
the domain name is stripped out like this:
href=\u0022http:\/\/default\/files\/Allergens.pdf
Why is this happening only when using the Drush command? I found I can fix it by adding this at the end of the command
--uri=mysite.com
So my new drush command looks like this:
drush vde myview myviewid myfile.json --uri=mysite.com
But doing this will hardcode the domain name into the URL. I want the URL to work on development, production and on my local. Thank you for any help you can provide.
$base_url
. Drush also might not know it when you have a multi-site setup. In both cases you can add the absolute URL as--uri
option to pass the$base_url
to PHP to let the code know under which publicly accessible URL your site is located. When rebuilding sitemaps for example duringdrush cron
. Simply adjust the--uri
option based on your environment. – leymannx Feb 8 '19 at 14:11--uri
But the url still does not contain the domain name. – paulcap1 Feb 8 '19 at 14:28--uri
isn't enough. You need to set an URL--uri=https://example.com
. With a little bit of Bash magic you could also try to get it from an environment variable. Or from some Git-ignored file like--uri="$(< sites/SITE_NAME/uri.txt)"
. And most likely there's even a way to define it in somedrushrc
file. But I don't remember ifdrushrc
isn't deprecated by now and don't know what the alternative is now. – leymannx Feb 8 '19 at 14:44--uri=mysite.com
to the command works. I am going to try makeing this a variable using this in our custom module$hostname = \Drupal::request()->getHost();
Then the drush command would be something like thisexec("/usr/local/bin/php ../vendor/drush/drush/drush.php vde myview myviewid ".$write_dir."/search-for-guidance.json" --uri=".$hostname.");
– paulcap1 Feb 8 '19 at 16:53