1

pardon the bad headline. I have a node with a autocomplete taxonomy field "categories". When a user creates a node, he can add a single term/category to that node.

How would you make it possible to also attach an image to that taxonomy in the same "create" or with ajax?

7
  • I would suggest you try the Taxonomy image module.
    – user16289
    Jul 4, 2015 at 11:18
  • Thanks, but it looks like it adds an image field to taxonomy items with some extras but adding an image field is already default in Drupal 7. Or am I missing something?
    – 0skar
    Jul 4, 2015 at 11:31
  • Than I'm not sure I understood your question. Do you want to create an extra taxonomy field instead of "Categories"?
    – user16289
    Jul 4, 2015 at 11:38
  • Sorry, no. That's simple enough with fields and Drupal 7. My question is how to create a new taxonomy term and upload and image to it while creating a node.
    – 0skar
    Jul 4, 2015 at 12:13
  • Hi, Oskar. Is this a preselected image or will the user who is creating the node be selecting/uploading the image? Aug 6, 2015 at 4:34

2 Answers 2

2

Might I suggest that you avoid taxonomy all together?

I am not a fan of taxonomy namely because it isn't a reliable way to tag your content. The most obvious is that any variation in the tags creates a whole new tag. For example, if you are doing a web site and you want to use the taxonomy of the different fruit:

apple != Apple

If you now go and create view to show all related content for "Apple", you won't get anything related to "apple." Technically speaking, you can have 256 (2^8 = 256) permutations of your taxonomy term; not very useful, if you ask me.

So, the question is, what to use then?

Use your own Content Types.

For example, I created a content type called "Section" and the only field I have in the content type is "Title" which I renamed to "Section Name". (You can ignore the "URL path settings field." This is because I had pathauto installed.)

Section Content Type

Next...create some Section Names by adding content. Here I have added two content types: Big and Little.

Listing of Content Types

And if you "Edit" or "View" that piece of content you will see that there is nothing but the one field that you created earlier.

enter image description here

Next, is to create an entity reference to that content field This is where the magic happens. In another content type like "Article" (or whatever you like), create an entity reference field that links back to the "Section" content type.

Here, I have a content type called "Static Content" with just "Title" and "Body". I added an entity reference field called "Section", gave it machine name of "field_er_section" for readability, and made it a checkbox/options type of selector.

enter image description here

When you create/edit the field, you must make sure you reference back the content type you first created, in this case "Section".

Choose the target bundle...

How does this all come together? Let's take a look at a new piece of content that we create....

I have a section type!

As you can see, we now have "terms" that the user can select rather than type out.

Where does this come in handy? How about Views? You can now add some filters based on your new "Section"

Views Filter

Execute your view and you have all content related to your new term.

Now, if we were to do this with "contextual filters" (found under Advanced in the Views page) you could base your view on the values in the URI. For example, using the section names in my pics above:

www.example.com/little/

That would display all content related to "Little." You could also create a block view that would display all the titles of related content based on the term in the URI.

Now, as for your specific question, how do you add an image to your taxonomy term?

This is a content type, after all. Just add an image field and that image will follow throughout your site.

I hope that gives you a direction to go in and a nice alternative to taxonomy.

0

You can use References dialog module with this patch

This module extends reference fields like the user and node reference fields by adding links to add, edit and search for references through a dialog. This allows for a workflow where the user can create all the references to a node at the same time as she is creating it, a process which sometimes get's a bit backwards, when a user for instance needs to create all the facts for an article.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.