I have a content type called "product" with a CCK field of type File/Image. I am using imagefield 6.x-3.7 to get the image widget. I am also using filefield sources 6.x-1.2 to add the "remote URL" option as I want to be able to upload an image with an external URL (e.g. http://www.imagesource.com/abcd.jpg).

When manually creating a piece of content at node/add/product, I see both the Upload | Remote URL options (see filefield1.png below). I can manually fill in the fields (and particularly the image Remote URL field), click save (I did not need to click on "Transfer) et voila! My node was created with that image imported from the external URL and now saved on my local server and processed with image cache, filefield paths and imagefield tokens.

Here is my question:

I want to use Node Import to automatically import thousands of nodes of this content type. I provide the image remote URL in a csv file but the problem is that, by default, that CCK field is expecting a local file. I believe this is because the filefield default option is the "Upload" from a local file option.

So mapping an external URL (in the csv file) to that CCK field which expects a local file results in an error message from Node Import that simply says that this CCK field is expecting a local image and not a remote URL.

Is there a way to set the filefield default option to "Remote URL" coming from filefield sources so that my CCK field would expect a remote URL instead of a local image (see filefield3.png below)? I believe this would solve the Node Import problem as Node Import only maps csv columns with CCK fields and executes the import.

When mapping the csv column to that CCK field, Node Import would only paste the external image URL in the CCK Remote URL field just like I did it manually.

Thanks for your help. I am really looking forward to finding a solution.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vandana79’s picture

Priority: Normal » Major

Hello All,

Looking for same issue , please reply.
Thanks in Advance

webgears’s picture

Project: FileField » FileField Sources
Version: 6.x-3.7 » 6.x-1.2

For the moment i've done it on a messy way.

i themed mythemename_filefield_sources_list() in my template.php and only changed the output-order in this line of code
$sources = array_merge($sources, $default); // first sources, then default

and in the fielfield sources module, file "filefield_sources.js" on line 30 i changed
$('div.filefield-source', context).css('display', 'none');
to
$('div.filefield-upload', context).parent().css('display', 'none');.

This works for me, but after next module update the changed js-code will be overwritten.

Marko B’s picture

I did it like this.

$('div.filefield-source', context).css('display', 'block');
$('div.filefield-upload').parent().hide();

$('div.filefield-sources-list', context).each(function() {
//$(this).find('a:first').addClass('active');
});

NeoID’s picture

Is it possible to remove upload and just enable external sources?

Marko B’s picture

hide the normal form, think its only way as external is connected to normal upload.

christinekdo’s picture

Confused on how to get this working. deepM - I have found the lines of code you edited, and changed everything accordingly. Did you mess with the template.php file as well?

Marko B’s picture

Think this is it, just put that code and you should be fine, remote file would be your default.

golek’s picture

deepM,

I made the changes to filefield_sources.js like you said and it seemed to work, at least it allowed me to move forward in the import wizard. But when it goes to the preview import screen in the import wizard, I get this:

Input error: http://example.com/files/images/image1.jpg is not allowed for Image (not a file in sites/default/files).

where the path listed in the error is the value that is in my .csv import file. It still seems to be looking for the files to be physically located on the local server. What am I missing?

k3n3dy’s picture

subscribing to this.

Also, is there a way to don't need to have the images imported into Drupal's file system? I mean, can we have just the external URL and still display images in views, nodes, etc?

Edit: digging a little bit more found my question answered in this topic http://drupal.org/node/661168

Marko B’s picture

Isnt media mover module that puts your files away on some other location and then load for example images remotly?

rancas’s picture

subscribe

yang_yi_cn’s picture

subscribe

etibmw’s picture

Hi DeepM,
i made the changes to the js file and yes the order of the fields has changed!!!
all is well you ask? well not all, in the node import i still get an error "Input error: http://bla-bla-bla.jpg is not allowed for item image (not a file in sites/default/files/)." the image is on a different server.
did you do anything to node import to get this to work?
did you find a better way to do this?
what will happen when filefield sources updates?!?...

any help is welcome
eti

asak’s picture

Hey Guys - same issue here ;)

We're looking to import content using the FileField Sources module.

@quicksketch - what's up man? are we gonna get this working or what? ;)
Seems like a very desirable feature request - if you can maybe give me a hint/direction i could help out.
Basically, seems like "best practice" would be adding support for node_import INSIDE the node_import module, specifically for FF sources, but i'm pretty sure there is a way to get it working without touching node_import.module.

What say you? ;)

@everyone - anyone got this working?

soraver’s picture

subscribe

jpsimon’s picture

Hey Webgears, thanks for that snippet it worked 99% perfect for me. The only thing is... although Source URL was now default, the hint text wasn't showing up on page load. To fix that just add the following right above $('div.filefield-upload', context).parent().css('display', 'none');

add this:
Drupal.fileFieldSources.updateHintText();

quicksketch’s picture

Component: Code » General

@asak: If you write the feature I'll be happy to include it. I don't have any need for this feature.

plato1123’s picture

Subscribing

quicksketch’s picture

Title: Filefield source "remote URL" set as default option » Filefield source "Remote URL" (or any other) set as default option

Updating title.

mducharme’s picture

I think the way to go about this is to do the following:

1. Add the "default" Upload source to the list of file sources on the field instances edit page so that it can be disabled.
2. Add weights to the source list to drag and drop the order in which they are displayed, defaulting to the first in the list.

I may take a stab at this for the D7 version if people are still interested. What say you quicksketch? Do you still not see a need for this? It seems useful enough if only for migration.

quicksketch’s picture

@mducharme: I've changed my mind on this one and if you write a patch I'll commit it. At this point I'm not very interested in maintaining the D6 branch further but I'm not sure if we should branch for 2.x. If we did, this seems like it would be a good opportunity to do so. Then we could add #1768740: New Source: Paste from Clipboard to just the 7.x-2.x branch too without a backport. What do you think?

quicksketch’s picture

Marked #879902: Disable upload widget for special cases duplicate of this one. Let's make sure to include the option to disable the upload field.

quicksketch’s picture

Title: Filefield source "Remote URL" (or any other) set as default option » Filefield source "Remote URL" (or any other) set as default option (aka Disable Upload option)
rudiedirkx’s picture

I'm looking for this too. The separate contrib module filefield_sources_noupload doesn't do the trick.

Since I'm not doing anything tonight... A patch might be forthcoming.

rudiedirkx’s picture

Patch for 7.x-1.x-dev. I've attached screenshots to show the new functionality.

This patch changes the way the default upload 'source' is handled. It also (slightly) changes the way custom sources are processed. Combined, that's why it's a big one.

It adds a new source: "Disable upload" that removes "upload" from the sources list.

It doesn't add the "default option" part. That's something else entirely. All the JS could be rewritten IMO, keeping the same functionality in fewer lines. (The only thing JS should be doing in this module is switching between sources.) With new JS, the default option could be simple. I'm not doing all of that in 1 patch though.

It also adds [placeholder] attributes where they should've existed a long time. (Instead of all the JS.) Necessary because the JS isn't executed for fields that have only 1 custom source (because their <a> is never clicked). The downside is that IE9 still doesn't have [placeholder], so in IE9 the fields that have only the "reference" or "remote" source don't show a placeholder (and won't when you focus the textfield).

Most of my time went into finding a solution for IE users (failed). The solution could be very simple: add a [placeholder] polyfill. I can't be bothered though.

rudiedirkx’s picture

And if you select only "Disable upload", it will ignore itself.

rudiedirkx’s picture

Nooooooo! The new source file isn't in the patch and I've deleted it locally... So sad.

Will reroll patch soon.

dariogcode’s picture

In meantime I'm using this (I have plupload source and want it to be default):

function mymodule_preprocess_filefield_sources_list($variables) {
	drupal_add_js('
		  jQuery(document).ready(function($) {  
		      $(".filefield-sources-list").each(function() {
      			$("a.filefield-source-plupload", this).trigger("click");
      			$("a.filefield-source-upload").hide();
      		});
		  });'
	  	,array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));
}

Insiprated in this: http://drupal.org/node/1760272#comment-6668434

rudiedirkx’s picture

New patch. Ignore patch file in #26. Screenshots match.

rudiedirkx’s picture

@darioarg That would do it. This would probably be enough JS though:

jQuery(function($) {
  $(".filefield-sources-list a.filefield-source-plupload").click();
});
rudiedirkx’s picture

And you made me miss my comment count =) Now my patch has -29- in its name...

dariogcode’s picture

I had to use js beharvior because when file is uploaded widget is reloaded

function mymodule_preprocess_filefield_sources_list(&$variables) {
	drupal_add_js('
		  (function ($) {
				
      	               Drupal.behaviors.fileFieldSourcePluploadDefault = {
  				attach: function (context, settings) {
    				  $(".filefield-sources-list a.filefield-source-upload").hide();
      			          $(".filefield-sources-list a.filefield-source-plupload").click();
  				}
			};
      	
		  })(jQuery);'
	  	,array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));
}
rudiedirkx’s picture

Yeah good point. Nice way to hide the upload field too =) Both should be easy when my patch lands.

rudiedirkx’s picture

Alright, this one fixes everything:

  • New source to hide Upload
  • New settings to choose a default source (no sorting, just 1 default)
  • [placeholder] for real browsers (and a new bug for stupid browsers....)

If this patch lands, I'll fix the placeholder bug appropriately. (All relevant code out and a polyfill in.)

rudiedirkx’s picture

Any takers? Any movement? I'd like this in FFS. With this, I won't need Media.

mducharme’s picture

Did you try the latest patch?

rudiedirkx’s picture

I created the latest patch. I think it's the greatest.

mducharme’s picture

Patch works very well. Nice job.

The only thing I would change is to invert the Upload option. I think it should just be called "Upload" or "Default Upload" and be checked by default to match the behaviour of the other options in the list.

Interested in your feedback before marking this as RTBC. I can help out with this change.

rudiedirkx’s picture

I agree, but that would be a big change requiring a tricky update path. I kinda like one source being able to cancel out others =) Very dynamicy.

Rewriting to that would be a lot of work. (I'd start over, not use this patch.) Not worth it IMO. Ofcourse if you disagree, you're very welcome to repatch. I'll be more than happy to review and test. I'm not in a hurry.

quicksketch’s picture

This looks like a nice patch. I agree with @mducharme though, we shouldn't add a checkbox that you check to *disable* something. Checkboxes should always enable if checked. As he mentioned, we should make it checked by default so you uncheck to disable.

In truth writing an upgrade path is not feasible, there are too many sites that use features to export their fields to code, so we would need to handle this in a way that is backwards compatible (or make a 2.x branch, which I don't think is necessary). Even if we want to store the option like we do currently, we can simply flip the UI presentation so the presence of the setting will uncheck the checkbox, and if it is not present (like it won't be for all existing installations) we check the upload box.

rudiedirkx’s picture

Fair enough. So this will take a looong time to be fixed =(

mducharme’s picture

Just so I'm clear, it's specifically the lack of support for Features that would block this from being committed? I wouldn't want to waste time if this ultimately ends up "won't fix".

rudiedirkx’s picture

Features? How is Features relevant? It's partly (mostly?) backward compatibility that makes your and quicksketch (and mine) preferred solution difficult. My solution is backward compatible, but kind of weird.

rudiedirkx’s picture

Status: Needs review » Needs work

I agree though.

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
6.71 KB

That was much simpler than expected. And much cleaner than my last great idea.

To do (in other patches):

  • somehow allow reordering sources (the first one will always be the default)
mducharme’s picture

Status: Needs review » Reviewed & tested by the community

Works great! All source combinations tested and working. If all sources are disabled, the default standard upload is used.

quicksketch’s picture

Thanks for the adjustment to code. Yes, as you found, this wasn't really making things significantly different, we just needed to check if the 'upload' option had not yet been set and then default it to be enabled. This new patch does exactly what I had hoped-for/recommended.

The only significant remaining problem is that this line doesn't actually provide any static caching:

$cache = drupal_static(__FUNCTION__);

In order to work, the return value needs to be by reference:

$cache = &drupal_static(__FUNCTION__);
rudiedirkx’s picture

Oeh good catch. I always use a helper that takes a closure, but that's too modern for popular D7 contrib.

You can patch and then fix the & if you want. I don't need mentioning or credits. I need this this issue fixed.

Will you?

mducharme’s picture

I'll post the updated patch tomorrow morning. I've only got one other patch committed so I could use the cred :)

quicksketch’s picture

Of course I'll mention everyone in the credits. Before I commit this (and especially before a release) I need to test it hands-on. I've got a major launch this week so it's not likely to happen immediately. I *will* say that I promise this will be in the 1.8 release, so you can run the patched version until that release is out (or at least until I commit it to dev so you can download that instead).

mducharme’s picture

Attaching updated with the pass by reference tweak. I'm somewhat new to Drupal patches; did I attribute to rudiedirkx properly?

rudiedirkx’s picture

@mducharme I don't think your should include the entire git show. Only the diff. The commit message will be up to quicksketch. It's not a pull request ;) We're not that cool.

mducharme’s picture

I was using the 'advanced patch guide' to be a hero. Here's the straight diff.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs review

Damn, that's a beautiful diff! Pure pro! ;)

Will need new review now though. Who knows what you've changed since #46. We'll wait for @quicksketch.

webadpro’s picture

Any updates on this patch?

rudiedirkx’s picture

@webadpro Did you try it? See the code? I'm biased so I don't count.

mducharme’s picture

I'm biased too but it works like a charm on my sites. Hopefully this gets committed before someone like me requests google drive and dropbox support.

webadpro’s picture

I did try it. Works like a charm.

webadpro’s picture

I did try it. Works like a charm.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Just tested this with SimplyTest.me and it worked just as @webadpro said.

dariogcode’s picture

I don't know if this is related, but when another than default upload option fail (form validation) it show the default upload option with the message. For example, I'm using remote upload, if upload fail, it show Plupload (defined by default) and the error. Make sense? My apologize for my bad english.

Of course I applied the last patch (#54)

muschpusch’s picture

tilon: i can't reproduce that and the code looks good.
+1 for committing.

eminencehealthcare’s picture

I can confirm #54 works great.

mgifford’s picture

@tilon I didn't follow about the problem you were having. Sounds like #54 didn't resolve it, but not sure if #54 caused it either.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed
FileSize
2.11 KB
6.81 KB

Thanks guys!

I reviewed this and it works great! It's a very nice enhancement. I tried it out with plupload to use it as the default and it works fantastic. Very nice to have the ability to simply disabled the upload field and replace it with a better one.

I did find a few minor things that I corrected:
- I used triggerHandler('click') instead of .click() in the JS. This prevents firing browser behaviors upon click (such as causing the page to jump down to where the link is).
- filefield_sources_info() was missing some t() calls around the default upload strings.

And I did some minor reformatting of the code just to make it feel more consistent with the rest of the module style.

rudiedirkx’s picture

Excellent! For the interested: http://drupalcode.org/project/filefield_sources.git/commitdiff/83bad95

(Busy day, the 24th! =))

@quicksketch How did you attribute to me so the commit list says "authored by rudiedirkx, committed by quicksketch"? I tried that once and failed. Extra git options? Not with --author, is it?

quicksketch’s picture

Yes, it's with --author. I took your e-mail address from your profile page. Normally I don't bother with author attribution (instead I just include authors in the commit message itself), but this issue made kind of a big deal of it so I made sure to include it. :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

SeanA’s picture

This additional functionality is very nice, but it's not 100% there. It doesn't allow selecting a different default method if "Upload" and one or more others are enabled. See comment #46.