One thing which our users have found unintuitive about this module is that the description field is not used when inserting links. For instance, say I upload a PDF file named "Brochure 2010-01-30 v2.pdf", and then give it a description of "Brochure". When I click the Insert button, I would like to see the text in my WYSIWYG as "Brochure", rather than the (usually) non-sensical uploaded file name.

Is that something which can be configured already? If not, can this be the default behavior? Perhaps if there is no description field, or if it is empty, then use the filename; otherwise, use the value in the Description field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Category: feature » support

You can change the behavior by theming the inserted content. Just copy the insert-link.tpl.php file to your theme directory and make whatever changes you want. Then clear your Drupal caches so that the new .tpl.php file will get picked up.

geerlingguy’s picture

Is there a possibility this could be a configurable option in the Insert settings for the filefield? This is pretty much a baseline requirement for all the sites on which I install this module, and it's never fun to create more .tpl.php files for an already crowded theme directory :-/

joelstein’s picture

I agree with geerlingguy; this is a pretty obvious default behavior. Besides, I tried changing the contents of insert-link.tpl.php from...

<a href="<?php print $url ?>"<?php print $class ? ' class="' . $class . '"' : '' ?> title="__description__"><?php print $name ?></a>

...to...

<a href="<?php print $url ?>"<?php print $class ? ' class="' . $class . '"' : '' ?> title="__description__">__description__</a>

...which works, but only if there is a value in the description field. If there is no value in the description field, then an empty <a> tag is inserted, which is not obvious to the average user.

What would it take to change this behavior? Shall I submit a patch?

joelstein’s picture

Sorry, in that last comment I tried to write <a> and messed up the formatting.

geerlingguy’s picture

To fix this, we could either have the file name automatically populate the description field, or perhaps have the __description__ placeholder revert to the filename if the description is empty... ?

Patch would be great.

For now, I'm using

<a href="<?php print $url ?>"<?php print $class ? ' class="' . $class . '"' : '' ?> title="__description__">__description__ - <?php print $name; ?></a>

... which at least prints the - file_name.ext if there is no description.

perandre’s picture

+1 for using description if available by default.

Maguar’s picture

When I shake Inserts inserted code with the wrong encoding for example <a class = "highslide_formatter_default highslide" href = "/% 3Cimg% 20src% 3D% 22http% 3A /% 252F.... %22%20alt%3D%22%22%20title%3D%22%22%20%20class%3D%22imagecache%20imagecache-highslide_full%20imagecache-default%20imagecache-highslide_full_default%22%20/%3E">
Where to find the error? FCKEditor or Insert. Pleace Help

pribeh’s picture

Quad-super Bump.

igorik’s picture

There is no description for images too.
I inserted a few images, but in the code of images, there is no description I filled for each of these images.

igorik’s picture

Category: support » bug

changed to bug report, image could be inserted completely with description

quicksketch’s picture

Category: bug » support

This is not a bug since it is not the intended behavior as it was designed. Not all files have descriptions to use. If someone writes a patch I'll review it, but I don't have a personal need for such functionality.

igorik’s picture

Hi, thanks for quick reply.

IMHO Filefield = file + it's description(if it has some).
You wrote that no all files have description - yes, if there is no description, no text info is inserted. Same as it is now.
And while the file has some description, it could be inserted together with the file (title, or alt, and some text under the image), if not, the filefield info is not complete.

gooddesignusa’s picture

I would also like this functionality. I will try to write a patch when i have some time. Using geerlingguy example but modifying it with some logic to just check before it prints.

riisi’s picture

subscribing

geerlingguy’s picture

Perhaps this could be implemented in the same way as core's File Attachments work...

When a user uploads the file, the file name is inserted as the file attachment description automatically (replacing underscores and/or dashes with spaces). Then the description would always be used, no matter what, and this issue would be moot.

Of course, this would probably have to be an issue over in the FileField queue... maybe a checkbox in the filefield's settings for 'Use file name as Description' for fields that have the Description enabled for use...

quicksketch’s picture

Then the description would always be used, no matter what, and this issue would be moot.

As far as I know, if a description is empty in Upload module, it uses the file name also. Forgive crudeness but I'm just attaching a file directly to Drupal.org to demonstrate.

quicksketch’s picture

Yep, so it seems that "no description" == "use file name" in Upload.module also.

I think the request here is just to default the description to the file name and keep all other behaviors the same. I should note that if this change moves forward, it should be addressed in Drupal 7 first, which now uses FileField and defaults to no description also.

geerlingguy’s picture

FileSize
33.06 KB

Well, yes; however, immediately after the file is uploaded, the Description is filled in with the file name, and then the user may delete that description and add his own, or simply modify what's there. I find that to be much more intuitive than having a blank description, then showing the filename after saving... (see attached - I didn't have to type in the file name).

Maybe I'm just confusing what you said in the last post...

quicksketch’s picture

Yes, I'm just saying if you delete the Description that is pre-filled for you, Upload.module uses the file name on display. So we couldn't "always just use the description" because the description may be empty. FileField already acts like Upload module on display, the only difference is upon uploading a file.

geerlingguy’s picture

Okay, I see.

mherchel’s picture

Is there any way that someone can program something like: If Description exists, then write description. If not, then just write filename?

I tried for a while, but I can't get the isset or empty php functions to correctly detect if the description was filled in (I'm obviously not a programmer)

quinns’s picture

I figured this out, at least in the context of my projects. If you are using a different "admin theme" than your front-end theme, you need to copy the template files into your admin theme folder.

aiphes’s picture

i suscribe to this feature...very useful for basic contributor.

attheshow’s picture

Category: support » feature

Subscribing.

Also, I believe this should be marked as a "feature request" based on the discussion above, so I'm changing that as well.

sylvain_a’s picture

+1

mzwyssig’s picture

Subscribing. Any news on this feature request ?

pribeh’s picture

The maintainer has noted that they will not be working on this feature so it would make sense for someone else to begin work on it. I will see if I can get a developer to start work on this soon. Anybody else willing to pitch in bounty-wise?

johannesdr’s picture

FileSize
1.47 KB

Why is __description__ used in the template file, while all other data is available in php variables?
I made a simple change to the template_preprocess_insert_link function and the insert-link template to pass the description as php variable. This solves joelsteins problem in #3
Patch is included.

quicksketch’s picture

Why is __description__ used in the template file, while all other data is available in php variables?

Because description and __alt__ are not known until the user clicks the Insert button. So imagine this use-case:

- User visits node/add/story.
- User enters title of node.
- User selects an image to upload and clicks "Upload". At this point an AJAX request is made and the file is handled. The returning HTML includes the file name, the "Remove" button, the empty Alt and Description fields, and the "Insert" button.
- The user enters the Alt and Description.
- The user clicks Insert, which reads the Alt and Description text from the fields and swaps them into the template, then inserts the template into the body field.

So in short, you can't use a PHP variable because it will always be empty for new files or it won't be accurate for files if the user changes the description before clicking insert, since Insert doesn't make any kind of AJAX request when inserting a file (which it shouldn't, it already has all the information necessary on the front-end side).

quicksketch’s picture

Well, given enough time I suppose I may eventually get to anything (14 months later). This patch adds support for several new tokens:

__filename__ (not a big deal since we already had $name before, file name never changes)
__description_or_filename__
__alt_or_filename__
__title_or_filename__

I've also made "__description_or_filename__" the default token for file links inserted, so if you enter a description it will be used as the text of the link, otherwise the filename will be used. As usual, you can theme the existing tpl.php files if you want to change the default behavior.

perandre’s picture

*Like* :)

geerlingguy’s picture

Double like. Thank you so much for this! Will there be a new release posted soon, or should I grab it from git?

quicksketch’s picture

Yeah I *just* posted the 1.1 release. So you can try it out as soon as the packaging script finishes. Drush usually has a slight delay before releases become available.

joelstein’s picture

Sweet! Thank you for adding this.

Status: Fixed » Closed (fixed)

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