Shoudl I use CCK for everthing?

Events happening in the community are now at Drupal community events on www.drupal.org.
dkinzer's picture

This is a newbie question, so please forgive me if it's obvious (my copy of Pro Drupal Development doesn't cover it):

I am writing my first module. It needs to use a table with zip-codes and regions and other attributes to work. My first inclination is to add this table to Drupal. But I was asked if I could create a new content type and import these records as content (unpublished). That way if any

changes needed to be made to the table, someone could do it without having to use mysql or PHPMyadmin directly. I said sure this is possible. Albeit these records would never actually appear on the site because they are only needed for background calculations (so technically it's not content).

I know that this technique would add a lot of other fields to each record that we will potentially never use. However, I'm wondering if it's the norm to use such a technique or should I advise otherwise?

Thanks for your insight on this one.

David

Comments

Hi David, I'm fairly sure you

andyf's picture

Hi David,

I'm fairly sure you don't want to be using a tool like phpMyAdmin to regularly change data (even custom modules') for your Drupal site.

this technique would add a lot of other fields to each record that we will potentially never use.

You mention CCK in your title: while that is one way of creating a new content type, you can also do it programatically with control over the schema. Having said that, you might well find that the storage overhead introduced in the tables node and node_revisions is not so bad; especially as it's possible to have the same field attached multiple times to a single node. A bigger consideration might be playing nicely with other modules that work with CCK fields.

Can you give some idea of what data you want to store, what you want to do it (what queries, how often), and what size datasets you're thinking of?

Thanks,

Andy

Hi Andy, Thanks so much for

dkinzer's picture

Hi Andy,

Thanks so much for your reply.

In answer to your question, the type of data is a collection of zip-codes, city name, state initials, distance (measured in miles from our local zip-code location), and a billing area category(either local, regional or remote). What is considered local or regional is subject to change and does not tie in generally to any distance (so I have to use this rather arbitrary table).

Users will run through a membership wizard that will determine among other things what region they are from. So the query will happen against the zip-code they input vs. our table. It's hard to tell exactly how often, but I guess there will be a regular and relatively high frequency. The table on the other hand will not change regularly).

The table consists of about 800 zip-codes. Any zip-code outside of this set will be considered 'remote'.

Best regards,
David

Take a look at the location module

cjdavis's picture

Hi David,

You should take a look at location - http://drupal.org/project/location - it will actually do most of what your table does, in particular figuring out distance between zip codes - that would save you the effort of importing and maintaining your own data on the same subject.

-Chris

bg1's picture

I am a database developers who designs and builds large databases and Data Access components. I am a Drupal newbie who has been trying to build a web site with little or no programming (is that at all realistic?) and trying to use CCK for all content types (tables). I have been going crazy for a number of reasons.

  1. I have a great many tables and many of these are simply cross reference tables for many-to-many relationships between other tables. The time to enter the many tables with a large number of fields, is painful.

  2. I have not found how to suppress all the CCK functions such as Input Settings, Menu Settings, URL Path Settings, etc. so they do not show up on the CCK Content Creation forms. I have also not figured out how to customize the look and feel of the Content Creation forms.

  3. It is common to want to have content creation screens that populate/update a number of tables in one pass. I do not know how to do that with CCK.

  4. I have not been able to figure out the myriad families of competing add on modules to CCK to get them to work reliably.
    E.g.,
    a) I use CKEditor, should I use with CKEditor Module or with WYSIWYG Module?
    b) Should I use the Images family of modules or the ImageCache and Resize Modules? (E.g., Images that I insert into text areas that display fine in preview mode, are nov visible in view mode. I have also never managed to get Image to show up in the field type drop down when creating a new field in CCK - I have selected file and then Image in the Widget Drop Down, but the videos I have seen show selecting image as a field type).

If someone tells me all this is possible with CCK and I just haven't figured it out yet, I will continue to try, but if trying to do the things I am trying to do with CCK is unrealistic, I will look for other solutions (any suggestions would be appreciated).

Thanks for any suggestions.

some answers, some questions

MamaGubs's picture

I am still somewhat of a newbie to Drupal, though I guess now that I've created a few applications and sites, including lots of images, workflow, advanced actions, etc., I'm probably about a 5 or 6 on a Drupal scale of 1 to 10. I use Drupal 6, so all my answers will be in that context. If you are just starting, that is what you should use.

I am curious about very experienced Drupalers on the question of reference tables, like the zip code table mentioned above, but that said, Drupal is designed to have its data tables as nodes. There really are not a lot of extra fields added, and by doing it this way, you know that any modules out there will work with it. Off the top of my head, I can think of three reasons you might want to store your zip codes as nodes:

  1. Views and editable fields modules - easily create a view that shows your zip codes in a table where you can directly edit the fields
  2. Views and Views Bulk Operations modules - you've decided you want to add a field to the zip code table, where many nodes will have the same value. You can add the field to the content type, and if then update the nodes quickly by setting up a bulk operations view. (bg1, this is your answer to #3)
  3. Views and node reference modules - you want see which customers fall into a particular region - you create a view with a relationship to the zip code table, and with a filter that allows you to select the region. The table displays the customer name and other pertinent information.

bg1, do the cross-reference tables already exist? I have not had to do this, since my apps were all new, but I just did a quick search on modules and see a node import module that may work. http://drupal.org/project/node_import

I use ckeditor in Drupal and love it. Definitely use it if you like it. You just need the ckeditor module and the ckeditor itself. Download the ckeditor module, then download the ckeditor itself from the ckeditor site. Make sure you put the contents of the ckeditor editor folder in the right subfolder of the module. The right folder has a "copy here" file.

The content creation forms have been, in my mind, a bit of a weak link in Drupal, but I've found over time that it doesn't get in my way much. There is a concerted effort to make this MUCH better in Drupal 7 from what I understand. (remember that you will not be able to move to Drupal 7 until all the modules you use support it)

I have not worked with videos. I use imagefield and imagecache modules mostly for managing images, and views slideshow. I haven't had any problems. I'm not sure I'm following what you're trying to do there, so perhaps you can give a little more information?

Drupal is pretty bare bones out of the box. The power is in the contributed modules. Here are the ones I use (I might be missing a few, but this is what I quickly picked off from my installations):

What I can't imagine living without:

Views (did you figure that out yet?)
CCK
(views and cck are so important to doing anything with Drupal, I just can't image Drupal without them)
views_bulk_operations
admin_menu
advanced_help
backup_migrate
ckeditor (or other favorite)
imagecache
imagefield
pathauto
poormanscron (if I don’t have access to crontab)
login toboggan
custom error (custom 403 & 404)
ajax
token
date
nodereference (cck field)
userreference (cck field)

What I find very useful depending on what I'm doing

panels
calendar
content taxonomy
printer, email & pdf version
ubercart (for ecommerce)
automatic nodetitles (this could come in very handy for reference tables)
fivestar (and votingapi)
thickbox
taxonomy manager
computed field
vertical tabs (makes #2 in bg1's list much better)
workflow

For site traffic

NOTE: I'm just beginning to start down this road - these are modules I've found that I'm checking out
google analytics
xmlsitemap
nodewords
service links
twitter
seo checklist
addthis
invite
ad
forward
chatcatcher
opencalais
pingback

Development aids

devel
firebug (unrelated to drupal - firefox debugger plugin)
drupal for firebug
Eclipse and xdebug (for full IDE)

Hope that's enough to get you started. Drupal does have a long learning curve, but the more you work with it, the more you'll be amazed at the complex apps and sites you can put together in a very short period of time with little to no programming.

have fun!

Mama Gubs

Thanks Mama Gubs here is more info

bg1's picture

Wow, you covered a lot of territory. I will address just a few of the issues I am having.

  1. CCK:
    1. If I use any HTML to bold, italicize, set font color within a test field (not text area), it is ignored whenever the content is displayed - there really does not appear to be a way to format parts of the content of a text field.
    2. if I want to define a field as an image field, the video's show that there is a video option in the field type drop down. I do not have image as an option in the field type. Do you?
  2. CKEditor, Input Formats, CKEditor Configuration and Images inside of Text Areas:
    1. I have installed CKEditor Module and CKEditor and in general they are working ok.
    2. However, if I use any of the formatting within the text area, it often does not display in the node. I find the combination of Input Formats, CKEditor Configuration and the Text Field Configuration (field settings and then global settings) to be totally confusing. What controls what is happening when.
  3. CCK with Images
    1. Often, I want to include images inside the text areas (imagine the user writing a "how to" text with lots of screen shots). The user needs to be able to resize the images, control their placement for display, etc.
    2. I have Image Cache, Image Field and Image Resizer installed.
    3. I add a field where field type = file and widget = image. The user can drag this into the text area and set the properties for the image - alignment, etc.. Multiple problems start from there however:
      1. The image is always a thumbnail. Therefore if I resize it larger, the quality is terrible. What do I have to do to have the image I drag into the text area be a larger image.
      2. If I get the image to look ok in the edit mode, and then view it in the preview mode, the image is there but it usually does not adhere to the image alignment I set in theproperties.
      3. Even thought the image is there in the Edit-Preview, when I save the edit and look at the content in Node View, the image does not display. When I look at the source in the browser, the image URL is there (the same URL that works in Preview mode) but the image does not display. The only way I can get the image to display in the View mode is to hard-code the full URL starting with http:// in the image property in the text area content. I don't think this should be necessary.
      4. I cannot find where most of the images are being stored. When I go to the folder hierarchy in the operating system of the server, I find all the folders under imagecache or subfolders under iamgecache to be empty, yet there are images in the images and the imagefield_thumbs folders. Where do the image files get stored in your case?
  4. Images in general
    1. I have a node where the node type itself is images.
    2. I have stored a number of images in this content type.
    3. I have set up a view where the format = Slideshow, and defined it as a block.
    4. It works great, but I would like to resize the image size (I.e block size on the fly so that the slideshow width is such that it will fit in the width left over in the screen). I have been told that Image Cache will do that, but if I only install image cache, I do not have a node type = image. Do you create a standard Node content type for your images? What fields do you define? Do you have an example?
    5. Have you been able to create other image contructs, such as a images carousel or marquis that causes a number of images in a banner on the screen to swap out? How did you do that?

Thank you for any information you can provide and I hope I am not abusing your helpfulness.

Thanks, again.

some thoughts

MamaGubs's picture

CCK field formatting - to change the look of the field outputs outside of the body field is a theming thing - that is another whole ball of wax. You might want to find a theme that comes close to the look you want, and then do some theming from there. There are all kinds of guides out there for theming, which I have not gotten into much yet. But you have control over the css file - you just have to be careful that you are not changing a class that will "break" other formatting on the site. Better, I think, to create new classes and use those where you need them.

Image field type - you need the imagefield and filefield modules. Which it sounds like you have - and yes, you choose file as the type and image as the widget.

ckeditor - yeah, there's a bit of a rub, which has had me tearing my hair out a couple times. Again, the theme is likely to override some formatting you do there. The best thing if you want to do some major formatting is to theme, not try to circumvent the theme in the body field.

cck with images - make sure you are choosing full html as the input format when adding/modifying the node. And you have to set the profiles in the ckeditor under site configuration, to make sure whoever is editing has the right permissions. Also, check input formats under site configuration and make sure those settings are right.

imagecache - you should be able to create new presets in imagecache and use those presets everywhere. If you need new presets, just create them. For an image content type, you would just add a cck imagefield and any other fields where you want to store more information about the image. An image content type is just like any other node until you start adding cck fields. I have done a slideshow with views slideshow, but have not done a carousel or gallery. It takes some playing around with imagecache to get an understanding of it, but it's a great module.

The biggest impediment to thriving on Drupal, I think, is how hard it is to find the best way to approach a given need. There's lots of stuff out there, but it's not easy to find and often you're not even sure what you're looking for. I would recommend joining http://groups.drupal.org/drupalversity, a new group that looks promising. Also, I stumbled across this resource http://www.listology.com/jwalling/list/drupal-beginner-resources which is an awesome list of resources for beginners.

Mama Gubs

Thanks I have tried some of these

bg1's picture

Thanks for the additional input. I have tried some as follows:
CCK field formatting. The problem is when you want to have different formatting within a text field. One could span the various text elements and have different classes for the different spans and then define those classes in CSS but the big problem is that the users who are creating the content do not know anything about any of that. They are end users who know how to use Word and other tools that allow them to format content. I have tried configuring CKEditor, Input Formats, the CCK field, etc. all with unstable results. I also found out about the permissions issue that the permissions are very sticky with regard to who can format their content how. I guess I have to take a much more formal approach to documenting every permutation of all those configuration parameters and see if I can find the combination that works.

I agree that it is probably the theming that is causing a lot of the problem because I can see that the html is getting into the content. It is just not paying attention to the html when generating the output. The source that reaches the browser no longer has the html (although I am using full html). Again, theming is not compatible with allowing the individual authors of content to be able to control many aspects about how their text appears within their article.

Images, Imagecache, etc. I will try creating the Image Contetn Type using CCK and ImageCache.

I will let you know as I resolve these issues.

Thanks again.

Isn't there a way to expose

dkinzer's picture

Isn't there a way to expose any type of object to Views now (not just $node objects)? So my module could still make use of Views by hooking into it and exposing my reference table data?

advanced_help

andyf's picture

There is yeah. If you install advanced_help you can see some documentation at help/views/api.

Wow, Thanks Mama Gubs Your

dkinzer's picture

Wow, Thanks Mama Gubs

Your insight is quite useful. And I completely agree with your thoughts on Eclipse and Xdebug.

+1 to Mama Gubs' excellent list!

andyf's picture

+1 to Mama Gubs' excellent list!

@bg1 - 1.a, 2.a, 2.b

Drupal stores exactly what the browser passes it in the db. When it comes time to display the data it runs through a number of parsers, which Drupal calls filters. The filters are grouped together into input formats. I imagine it's the filters in the input format you're using that are causing your problems. Regarding a CCK text field, one of its global properties is whether to interpret it as plain text, or to use an input format. If you want HTML to pass through, then you'll need to set it to use an input format.

The default input format Filtered HTML has (I think) four filters: HTML corrector, which tries to make valid HTML where necessary; HTML filter, which removes specified tags (prolly the problem you're having in 2.b); line break converter, which reads linebreaks and generates HTML tags (eg. <p>); and URL filter which reads an url and generates the <a> tag. Some filters are configurable, such as which tags are stripped in HTML filter, and you can change the order they act in, which can be very important.

When playing with a wysiwyg editor, you have to remember that the set of buttons you choose the editor to have do not affect the input format in any way. If you have a complete set of buttons, but a restrictive input format, you won't see much. But as I mentioned, everything's stored in the database, so if you change the input format after the fact, it will display correctly, which is nice:) And in case you're worrying about performing multiple filters on every display, the results are cached.

(Btw a very useful module when playing with formats is better_formats.)

Thanks Andy, here is where I am on these

bg1's picture

Input Formats: Default = FullHTML;
All Roles are enables for that Input Format
Filters = HTML Corrector, HTML Filter, Image Resize Filter, Inline Images, URL Filter (HTML filter says all the HTML I am using is OK)

CCK Field Global Settings = Filtered text (user selects input format)

CKEditor Advanced Profile:
Basic Setup: the Roles I use are enabled
Security Setup: HTML Corrector, HTML Filter, Image resize filter, Always run security filters for CKEditor.
Cleanup and Output:

<

p>,
and font formats specified.
as far as I can see other settings are for the editor while editing.

See my reply to Mama Gubs above with the title: "Thanks I have tried some of these". When I am in edit mode, the HTML is there. When I display results in a browser it is not. So I agree the theming is probably overriding something. I find that ok for certain HTML like font, but emphasizing, italicizing, bulleted lists, etc., should be things the author does and they don't even know what HTML is.

I will take a look at better_formats.

Strange. Could you post the

andyf's picture

Strange. Could you post the raw contents of the db and the HTML you get on node view? Careful about formatting: if you post between <code> tags it'll display ok. You can find the body contents in node_revisions, and the CCK fields are stored in content_* tables.

@bg1 - 3 I haven't used Image

andyf's picture

@bg1 - 3
I haven't used Image Resizer (Image Resize Filter?) but you might be interested in looking through the following discussions on inline images in general.

c. ii. Can you look at the source to see why the image is displaying as it is? Firebug (another of Mama Gubs' tools!) is very useful for this.

Image cache in general: It doesn't create a content type, it works at the filesystem level. It uses custom paths to create the image the first time it's referenced, and thereafter the file exists on the filesystem.

For example, I have a preset called small_thumb. If there's an image that references files/imagecache/small_thumb/img1.jpg then the .htaccess rules make apache first look to see if the file exists and if not (ie the first time) it passes the path as the argument to index.php. Imagecache has hooked that path and receives the arguments. It then looks for the file files/img1.jpg and applies the preset small_thumb, returns the image and stores it at the appropriate location on disk, so that future accesses will go straight from disk.

Obviously this can't work without something altering the paths from direct links to imagecache links. This is a facility offered by different modules. Views for example allows you to display an imagefield as any imagecache preset. Also if you go to Administer -> Content management -> content type -> Display fields you can alter the default imagecache preset to use (if any) when viewing the node normally. Some of the inline wysiwyg modules mentioned in http://groups.drupal.org/node/49658 allow you to use imagecache presets as well.

Hope that helps,

Andy

This is useful

bg1's picture

Thanks again for more guidance. It will take me a while to digest this and to describe exactly what is happening with my experiences (although I can say images are not being stored under imagecache (the sub folders are being created to match the presets, but they are all empty). The images end up in files folder directly, the images folder, or a folder names imagefield_thumbs or something like that (I do not have access to that server from my current location).

One thing I can say, however, is that when I embed images in my text area, It looks ok while editing and it looks ok in Preview mode but in view mode the images do not show. When I look at the source in the browser, the HTML reference for the image is the same in both cases. I don't understand why one works and the other does not.

I did notice that the image URL is ../../path from start folder to image (but in both cases!). If I modify the image profile so that it uses the complete URL from http://opt... on down, then it works correct everywhere.

Dunno. Do you have an image

andyf's picture

Dunno. Do you have an image toolkit installed? I've only ever used imageapi_gd (comes with imageapi, but needs to be enabled separately from the main module) which requires PHP to have the GD2 library installed, which you can check at admin/reports/status.

Sorry, scratch the last

andyf's picture

Sorry, scratch the last comment: if it's displaying ok on preview I guess you must have the toolkit installed. Can you create a test content type with a single imagefield, set the display to a simple imagecache preset, and check that it works?

@bg1 1.b) I don't really

andyf's picture

@bg1
1.b) I don't really follow you here...

4.e) There's lots of modules to do that. I've been using Views Slideshow quite happily, though it downloads all the images on page load, so it's not suitable for large slideshows. Check out a comparison page here: http://drupal.org/node/418616. Also some nice modules (various) at http://drupal.org/node/665756 but I haven't checked them out myself yet.

HTH

I like View Slideshow also

bg1's picture

I have also used View Slideshow and like it with the exception that I have been unable to control the width of the images. I think this is because I have created a content type images (which I think builds on the images modules rather than Imagecache) rather than a CCK content type. I will try that next with image cache and let you know what happens.

You can limit the number of

MamaGubs's picture

You can limit the number of images that show up in a views slideshow by limiting the items to display. I use that in conjuction with the random setting for slideshow sort order, so that my 650+ images don't bring the site to grinding halt :-)

Mama Gubs

But wouldn't it be cool if

andyf's picture

But wouldn't it be cool if only the first image loaded on page load, and the rest were ajaxed? Then you could, if you wanted, include large numbers of large pics. Also, even for smaller slideshows, it can be noticeable for them poor folk as still don't have broadband :) The slideshow issue tracking this is at http://drupal.org/node/323366.

Agree

MamaGubs's picture

yes, I agree, that would be very cool. Thanks for that link - I will follow that discussion

Mama Gubs