How do you migrate CCK fields between environments in Drupal? - drupal

The Content Construction Kit (CCK) is one of the most useful Drupal modules. It allows you to easily add custom fields to a content type.
However, these new fields are created through Drupal itself and stored in the database. This means that if you change a CCK field in your development environment you need to manually make the same change in your test and production environments.
Worse, there's no simple way to determine if your environments have gotten out of sync. So if you ever inadvertantly mess up or omit a change as you put it into test or production you may never realise.
I'm looking for a technique that allows me to export CCK field definitions that supports:
Importing into new environments (obviously)
Creating new fields
Ideally the export would also support:
Diffing
Modification of existing fields
Deletion of existing fields
Some kind of conflict resolution in situations where data clashes with field changes
The simpler and more repeatable the solution the better. I would like to avoid custom scripting or GUI automation unless there is a very clean way to do this.

Are you aware of the Content Copy module that is part of the standard cck package? It offers export/import functionality for fields and whole content types to some extent.
It does not offer diffing by itself, and I'm not sure about how well it does modifications of already existing fields, but it helps a lot for moving new fields and/or content types.
Also, you can save the output of exports from different instances and diff them locally, which gives you a pretty good overview of changes (especially revealing 'out of sync' situations quickly).
After enabling, check the new export and import tabs on top of '/admin/content/types'.

It is not that mature yet but the features module will allow you to do this. It packages up CCK fields (among other things) into drupal modules which you can distribute.

I personally use the Node Export module + Node Export File module (included, for CCK /image fields).
The entire node is exported into a textarea, as an associative array. The import form is similar: you paste the node array into a textarea. These processes are implemented as node operations, so they can be done in bulk (on the /admin/content/node page, or in your custom deployment module).
The benefit of this process is that you can modify the node data in transit.
Using a text editor, you can change the content type, title, add/remove/modify fields, whatever you want. Using a text editor with good find/replace, you can mass-edit hundreds of nodes. Since you have text, you can probably do all the things on your requirements list using existing tools or quickie scripts.

Related

Defining structure for content in drupal

I am trying to create a site that will enable users to publish their projecs and enlist other people to join their project.
A user should be able to list a project, specify certain attributes (name,description, etc..).
There are few things i'm having trouble with.
First, by default publishing content is refered to as "content", i dont want a user to "add new content" but rather to "list new project".
Second, a project should have certain attributes, some optional and some mandatory, rather then the default title and body,
users should later be able to filter by these attributes when searching for projects.
is there a way to define the structure of content?.
Third, a user should be able to apply to a project, if he applies, the owner of that projects should receive the appliance, and accepte\reject.
In case he accepts, the users profile should be added a record that he is part of that project.
I am completly new to Drupal, and CMS in general.
My main expertise is with java, and I initially thoght about building the site with a java REST api in the backend and angular js in the frontend, but I have 0 experience with security and dodn't know how to do the user authentication and session management.
So I am currently trying out Drupal.
Is Drupal the right solution?
If so, how should I approach the requirements specified above?
Drupal (assuming that you are talking about version 7 since 8 is still in beta) is pretty powerful CMS, with a lot of (free) modules allowing it to expand it's possibilities.
When you are in back-end under Structure -> Content types you can see all available content types defined. There is also link "Add content type" which you can use to define your own. That basically means you can add any fields in any types you want. If you don't see the field type you need there is a big chances that there is a module which adds that field type so you just have to install it. You can also remove body (hide it actually), but title must remain (but you don't have to show it on front-end).
There is a "node reference" field type, but you have to install a module for it: https://www.drupal.org/project/references
So you can create dependencies you like.
And that "add new content" is just a link - you can create your own, set title as you like, just keep the same path. You can also set different theme for (some) admin pages if you want them to look differently. Under Structure -> Menus you can even edit admin menu, add new link and stuff..
Drupal is a bit heavy on resources, because of it's complex structure and database abstraction. For static content just turning on (built in) caches will help, but generally adding some additional caching mechanism won't hurt.

How to create a node reference field using the CCK API?

We're currently building a module which automatically create content type, which allow to quickly install content types on any Drupal platform, without having to manually create hundred of content types and fields. In our previous versions, we were manually creating node reference fields and it works great. Now, we want to create it using our module since we have to add those content types and fields on dozen of platforms already under production; creating manually the fields would be a crazy idea. Do we have to use the node reference API? We are close to being able create it but, in VIEWS, the node reference fields do not appears. It seems we missed something. We're trying to check in the CCK php files to understand how the CCK API is used (if we can create it in a form then, for sure, we can code it). Any idea? Which API and functions should we use? I would like to know the proper method on how to do this.
You should use features rather than write code to create content types. Take a site w/ all the types you need, export them to a feature, integrate that with your module, easy as pie!

Drupal : how to create a view that displays all the content-types

It may sound 'weird' but I need to have a view that lists all the content types I have.
For example i have two content types : contenttypeA, contenttypeB
I want to create a view that just displays the two content types (and show number of items of that type, but that can be done later).
For now what I did is add one content of each content type and list them but only show the 'node type'; it works well if there's at least one content but I want to display even without any content of that content type.
Any idea ?
Introducing the node_type table to Views requires a custom module and some Views API knowledge however http://drupal.org/node/1001222 will give you a head start.
Use a Customfield: PHP code field and custom code the whole thing with PHP. This is provided by the Views Custom Field module.
Use the Table Wizard module to make the node_type table available to views. You may need to use the Data module as well since they say that all future development is going there.
Expose the node_type table yourself by writing a custom module using the Views API as suggested by chx.
Number one is the quick and dirty way, but number 2 might be a little more manageable, but I am not completely sure it will do everything you want. If you do number 3 make sure you contribute back to the community by putting your module on drupal.org.
There is no native functionality in Views to do that. You can write a static page or (overkill) a module that provide a "system"-like type similar to Views Watchdog.

Change how Uploaded Files to Drupal Are Displayed

When using the core drupal 'Upload' module, I get a user-friendly way of uploading files to my website and providing a download link on the page.
But the page is formatted like this:
Attachment Size
Somefile.doc 13.37mb
Article contents here
And I would rather it was the other way around, showing the article contents before the attachments. I have explored how to do this and come up blank.
I'm using the 'Garland' theme if it makes a difference to how I can implement a solution.
You must be using some module that changed that order. Or had it in use. Since Drupal-core has no way to re-order fields, and Drupal core upload-field has hardcoded its position in the form and in the display.
However, if you want to re-order fields in Drupal nodes, there are several ways:
The first option would be to solve this in your theme. But since you are using a vanilla (core) theme, changing the code of that theme is out of the question.
The second option, just as valid, but a lot more disrupting, is to involve the "CCK (content construction kit)" module. A warning is in place: this module is both complex and powerfull. Over 90% of the Drupal sites use this module, but since it is large and heavy, it will make your project a lot more complex, debugging a lot harder and performance a potential problem. Use CCK only if you think it fits well in your entire project, not just for re-ordering a set of fields.
The third option is to write a simple module that re-orders fields.
With hook_form_alter(), you can change the appearance, workings and order of fields in any form, including the node forms.
With hook_nodeapi(), you can change the behaviour of any node on many stages, including when it gets displayed: to re-order fields.
As said above: you may have such a module (with hook_nodapi) re-ordering your output, since Drupal core upload has the weight of that field hardwired.

Is it possible to change the content type on nodes in Drupal 6?

I have inherited a Drupal site on which (for some reason) there are two different content types for news: one for press releases and one for everything else. I would like to combine the two and use a taxonomy to categorize the press releases and other news types.
Is it even possible to do this? The site is using a number of modules, including Views and CCK, and I don't know how much a change like this would affect module data.
http://drupal.org/project/node_convert
The module linked above works extremely well for migrating nodes from one content type to another.
When you are done, you can then use VBO (http://drupal.org/project/views_bulk_operations) to mass manipulate the taxonomy changes you need.
Is it possible? Yes.
Is it easy? No.
To quote a well used phrase:
If it ain't broke, don't fix it.
You can get your site to work like you describe, and if you started with a clean site that you were going to build, it would be no problem. It's just a matter of choice. Now when you do have a database with views, content and other stuff, it wont be easy. You would have to:
Go through all the views, and set them up to use taxonomy and the 1 content type.
Migrate all the data into 1 content type. This might evolve setting up CCK for this content type to fit both, and take this into consideration when migrating the data.
It's possible the content types are used elsewhere, in custom modules, settings etc, these need to be tracked down and fixed as well.
So it's a lot of work with little/no gain.
Of course it's possible. The change won't necessarily be difficult if you've got a good understanding of how each content type is being used. You'll just need to be careful as it's a fundamental change.
If you think that the two different content types are not warranted and it is, in fact duplication of information then you could justify merging the two. Good house keeping!
You could phase out the unwanted content type over time and then when you're confident you've got it just right, build your self a merge module to move the old nodes into the new format. You could also build yourself test views and content types that you can dispose of later.
It may also help to install the devel module to get a programmatic overview of what your nodes look like. You shouldn't leave this module running on live sites as it effects performance.
Sometimes, there's a fair amount of crossover between content taxonomy and content types. It helps to ask yourself: What is a classification of an object and what's an attribute?
It is possible to change the content type of nodes.
The problem is if the content types use different CCK fields, which are present in a content type but not in the other. In such case, if you change the content type, those fields would not appear in the converted node; you should convert all those fields manually, or create a custom module to do that.

Resources