My situation is, when I click to add new content of lets say type "project", I want the fields be prepopulated with last entered values.. Since there is more then 40 fields, i don't want to fill every field individually..
Thanks
Well the answer may not be so simple. The best way i can think of is to create a custom module, hook_form_alter the node-edit form and change the #default_value of the form fields/elements you care about.
So in the defualt_value attribute of this you could implement a custom function that brings the data you need or hardcode the values
use devel module in drupal it creates content manually for specific content type i think it useful 4 u
Related
I basically have a content type named "articles", and in this content type there is a reference field (that let me put unlimited data) called authorsref and a text field which as well let's me add as many as I want.
Both of this fields are called "authors".
What I want to do is move a specific reference field, to the text field, and then delete that reference field.
So for example, there are a hundred articles already, there are actually thousands and let's say 40 of them have a reference field with the author test1 amongst other reference fields and let's say as well that 60 of those hundred articles have as well a reference field of test2.
what I need to do is to somehow go over all the articles and where test1 and test2 reference fields are present, move them from the reference field authorsref to the text field authors.
I am as well a newbie and I have been trying to get this to work for the last three days and I just don't know how.
Please help, and thanks so much!
I think you need to use hook_update_n + batch.
hook_update_n - With this hook you can update some values in your DB.
Batch - you need to use batch for operations that may take a long time. (You don't want to time out PHP, you wont worry about it with batch).
Some examples here and here.
Currently we are migrating our intranet from plone 2.5 to drupal 7. Everything works out pretty well except one problem we are facing with the cck module.
In plone we had one content type "application" which allowed our members to applicate for a specific project. There were many input fields for describing the required qualification from other projects like in the following "image".
project description
[ ][ ] + - up down
[ ][ ] + - up down
[ ][ ] + - up down
add new row
Our member had the possibility to mention an unlimited number of projects and associated descriptions.
So the problem is, i´m unable to do anything similiar in drupal 7.
I could definitely add an unlimited node reference field and an unlimited text field, but there would not be any kind of relationship between the two fields and the user would have to click "add another entry" twice.
Another option would be the use of the module http://drupal.org/project/tablefield but its not possible to use the first column as a node reference.
I´ve browsed through every cck module available and found nothing really helping, so now i hope you can help me!
Thank you
Have you tried the field collection module?
This helps you add a collection of fields as a single field.
So you could have 'Projects' as a "field collection" type field have unlimited number of values. You can then add the individual field like the Project name, description, etc. in the field collection.
This module is for D7.
New answer to an old question (but isn't that how Drupal usually works): you might want to try the Multifield module as an alternative to Field Collection or the other solutions posted here. It's meant for this type of problem.
The module Field group is creating this relation for you.
In Drupal 6 we can do this using Flexifield The project description page of flesifield says that similar functionality can be achieved in Drupal 7 using Combo Field. But I have never tried it though. It might worth giving a try.
For Drupal 8 you can also look into the Paragraphs Module for handling a multiple field with multiple inputs. Can be used for product properties, recipes and more advanced use case where a single field can behave like a content type.
There is also a module for Drupal 7 and Drupal 8 called Double field
Currently if you create a product in UberCart, you have to first create the product before accessing the stock tab to set stock levels. I want to be able to set the stock levels when I create the product. I.e. Right below where I set the "list price". How would I do this?
Well, that's going to involve a little work.
You're going to have to create a hook_form_alter implementation to add the new form fields to the node_add/node_edit form.
You're going to want to add a hook_nodeapi() implementation for $op=='validate' to make sure you're getting valid information.
You're then going to want to extend that hook_nodeapi() implementation for $op=='insert' and 'update' to grab the field value (which should be stuck to the $node object) and write it to the stock levels table, whose name I'm too lazy to look up right now.
Alternately, instead of 2 and 3, you could mess around with creating a validation and submit function, and append them to the #validate and #submit arrays of the form.
For people looking for a module-based solution to this problem in Drupal 7, the latest dev version of the "Ubercart Product Power Tools" module has an excellent per-product setting to make stock-tracking active on creation, as well as set default stock quantity and threshold for the product.
Ubercart Product Power Tools
Is there a way of creating a composite field that can have multiple values, with each value having another group of composite values?
E.g. we want to have this structure at the end:
Group 1 (unlimited number of groups)
Child field (unlimited children for each group)
Child field
...
Group 2
Child field
Child field
...
...
Is this possible at all for a custom module that defines a CCK field? If so, can someone push me in the right direction?
this is a very know and debated issue in the drupal world.
this feature is called cck "multigroup" and it looks it's pretty difficult to implement.
there are a lot of posts in the drupal forum about this, i suggest you to start here:
http://drupal.org/node/494100
it's a kind of "hidden" feature in the cck module. looking in the module directory, you will find instructions here:
cck/modules/content_multigroup/README.txt
Edit: Ongoing work on the multigroup module has moved to the experimental
CCK 3.0 branch.
in the meantime you can try to deal with it using the flexifield module
(but it's kinda hackish, i won't use it in production)
I ended up creating my own "Cost/Product" CCK compound field based on this excellent tutorial with example modules: http://poplarware.com/es/articles/cck_field_module
I haven't figured out yet how to pull out a specific sub-field, such as cost, in Views. I only get the entire ": $" compound.
For Drupal 7+, you probably want to check out the Field collection module, or Field group if multiples aren't necessary.
This issue is pretty old, but I just happened across it. I would think the way to handle it for now would be with a second cck type for the children, and the groups as a node_reference field. So you'd have:
MasterType
group field
unlimited per node
each one, a reference to a ChildType node
ChildType
child field
unlimited per node
i created a view that displays my homepage fine but now a modification is needed: i load 2 fields (images) in my view but need to only display one of those, depending on the value of a third (date) field and today's date. if date field is later than today, show image y and if its earlier than today show image x. this kind of logic cant be done in a view.
so in my template.php id like to output x or y as $vars['img'] in the preprocess_page function. im just wondering, how do i get at the values of those fields? its not a node but a list of node teasers.
the function gets passed &$vars but a print_r of those just shows the html output.
custom sql seems not the way to go.
when i load the view, i just get the html it outputs but (i think) i need the raw data to make the date comparison.
thanks for any pointers!
I'm sure there are some ways to do this, some more hackier than others. I would:
Make a template specific to your view
Create a preprocess function for the view and create a boolean variable, by checking which img that should be displayed.
Lastly I would alter the template slightly by making an if statement that checks if it should display img x or y.
This solution is pretty easy and straight forward, the downside is that it's not completely general as you most likely will need to know the names of the cck field names you are using. It's doubtful you would be able to generalize this anyways.
Edit:
To clarify a bit. You can look at the general views template that's being used, it will give you some insight as to how views prints the different fields. Generally getting at the fields is usually not a big problem when you have the $node object. The reason is that cck adds the fields to the $node object so you can access it there. I believe you can do something in the line of $node->field_[the_name] to get to the field. I would suggest that you use the devel module if you don't already and do a dpm($node) somewhere in the template where you loop through the nodes. That will enable you to see what has been defined on the $node object. It shouldn't be a big problem to print the img from there.
How about using preprocess_node() instead?