In this chapter, Karen turns on the Date, Date API, and Date tools modules, and walks us through some initial configuration of core date settings, so that we can use Date module properly. We look at the site timezone settings, as well as talk about the core date formats. Then we go ahead and create some new custom date formats and date types.
0:01[Configurations & Settings] [Dates with Drupal 7] [Chapter 2] [With Karen Stevenson]
0:06In this chapter, Karen is going to discuss the basic configurations of the date module
0:10and basic configurations in general.
0:12She'll begin with the modules required for the series
0:15and move into setting date-related variables in core.
0:18The steps that Karen discusses are the backbone
0:21for all future date-related configurations and integration.
0:25Today, we're going to take a look at the basic configuration of the date module
0:29and basic configuration of dates in general.
0:33I'm looking at a new installation--Drupal 7 Installation.
0:37Nothing is installed yet, and the only thing I've got available right now
0:42is the package that I downloaded for the date module from Drupal.org.
0:47If I go to the Modules page, and I collapse the core information,
0:51I can see that I have a whole lot of modules, and that's because the date package
0:55is actually a whole suite of modules that can be used in various ways.
1:00I might use some of them. I might use none of them.
1:04We'll be talking as we go through the videos about what all these different options are
1:09and how you can use them, but for now the only thing that we need
1:13is we need the date API, and the date API is the core of all of the date functionality
1:19and is required by everything else that the date module does.
1:24Then we want to create some date fields, and for that,
1:27we need to enable the date module and that makes date and time fields available
1:33to be added to content,
1:36and the last thing that we're going to do for right now is, we're going to enable
1:39the date tools module.
1:41The date tools module is a really handy tool that gives us a wizard that will
1:48get us started really quickly with dates.
1:51So for now, that's all I'm going to do is enable those.
1:56When I do that, I get this message up here that says that the date API requires
2:00that we set up the site time zone and first day of week settings,
2:03and that we also set up the date format settings.
2:06And what this is saying is that on the site that I'm using right now,
2:11these variables have not yet been set,
2:16and they need to be because the date module cares about how these things are set.
2:22So if I click through the first one of them,
2:25this is the regional settings.
2:26The regional settings is where I identify my default country,
2:30which I had to do as a part of the installation.
2:33This is also where I set up the first day of the week,
2:35and in the United States, we generally would have the first day of week be Sunday,
2:40but it could be Monday or perhaps another day of the week.
2:46The date module also adds this option to use the ISO-8601 week numbers.
2:52This is not something that most people are using probably,
2:56but if you're doing something with dates in a calendar, and you're in a country
3:03that you uses ISO week numbers for calendars instead of calendar numbers,
3:07which is a different kind of way of calculating what the week is,
3:13then you can check this box.
3:17If you do that, you have to set the first day of the week to Monday
3:19because the ISO week numbers require that the first day of the week be Monday.
3:24I'm in the United States. I don't need that, so I'm going to leave that unchecked.
3:29I've got my time zone already set up, and I also see that I have a place
3:32where I can designate whether or not users can set their own time zones.
3:35All of these time zone configuration settings can play into the way that the date module works.
3:43So I'm going to save that.
3:45Then the second place that I need to fix is, if I go back to
3:48the administration configuration screen, and I scroll down to the very bottom,
3:54I can see this regional and language section.
3:56These are core settings.
3:59I already fixed the regional settings, but I need to also fix the date and time settings,
4:03so I'm going to select that.
4:06And this is the place where I can set up formats for the way that dates are displayed
4:11on my site.
4:13Now by default, I end up with the 24-hour clock because that's what Drupal does by default.
4:19I'm in the United States. I'm going to change that.
4:22So I'm going to change my long, medium, and short settings to match
4:26the way that I want dates to be displayed in my system.
4:29So in my system, I want to use the 12-hour clock, and then I'm going to do this,
4:38where I'm showing the medium format is the full name of the month, the day, the year
4:44and the time using the 12-hour clock.
4:47Then for my short format, I want the month, day, year as numbers using the 12-hour clock.
4:59That's my particular way that I want to set this up.
5:02We're going to use this for the videos that we're working on right now,
5:04but you can obviously set those up to match something appropriate for your site.
5:11But there's another part to this.
5:12In addition to these long, medium, short types, we can also in the format options
5:18that come with it, we can also set up custom formats,
5:22and there are a lot of formats that are really useful when you're using date fields
5:28and using dates in general.
5:29We're going to go ahead and set a few up.
5:32Now nothing--no custom date formats are in here to begin with,
5:36so we can add a new one.
5:38We can see it just is a text area or text box where we can put in a date fomat string.
5:45There's a link here to the PHP manual that describes what these things are.
5:49I'm going to open this in a new tab just to make it easy to get to.
5:54I'm going to go over here, and this is what date formats look like.
5:59So date formats basically are a bunch of letters--a letter or a number of letters--
6:04that describe how you want the date to look.
6:07So for instance, a lowercase d says I want to see the day of the month in 2 digits
6:12with leading 0's, so it would look like 01 to 31.
6:15The j is the day of the month without leading 0's, so same thing as d--as the lowercase d,
6:23except the leading 0 is left off.
6:25The capital D says, I want to see the 3-letter abbreviation of the name of the day
6:32and so forth.
6:33You can read through this whole list, and you can see that there are letters here
6:40that represent various ways that you can look at dates.
6:45So what I want to do is, I want to create some additional formats that I've got available to me
6:49in my system.
6:51So 1 thing I might want to do is, there are places where I maybe only want
6:54to be able to see a year, so I'm going to add the capital Y as a format
6:58and a capital Y is the 4-digit year.
7:02I'm going to add a format for a lowercase j, which is the day without the leading 0's,
7:10and I think it would be nice to have a date format without the time,
7:16and that would look like month/day/year because I'm in the United States,
7:21and we use the month, day, year format, so I'm going to add that.
7:27Then it might also be nice to have a time without a date,
7:31and so if I do g, i, a--g means 12-hour clock:, i means minutes, and then a means a.m. or p.m.
7:43I can see that as I type these options in, they are displayed over here to the right,
7:48so I can kind of see what this is going to look like.
7:50I add that.
7:52That's pretty good, so I've got some additional options.
7:56If I go back over here to the types, and I open up my options,
8:00I can see that all these new custom options are now available to me as well as
8:03the options that I saw before.
8:06So that's one part of the equation.
8:08I've got some new formats available to me, and I could say
8:10I just want to change my short format to be a date only, for instance.
8:14But in fact, I probably want to just leave these original formats alone--
8:21or these original types alone--and add some new ones.
8:23So I can add a new type, and I can call it date.
8:26I could say my date format is this new format string that I just created
8:31that displays the date without the time.
8:35I can add a new type called time, and I can use, for that, I'll use that format
8:41that I just created that has the time without the date.
8:45Then I'm going to go ahead and add year that uses that format that I just created
8:52that has just the year in it.
8:55And I'm going to add day, and that's going to use this format that I created
9:02that has nothing but the day.
9:06So now I've got some nice additional formats available that I can use in various ways,
9:13and I can use these things in views.
9:15I can use them to format the way that my dates display.
9:18I can use them anyplace that the system uses this long, medium, and short format options.
9:25So let's go back to the modules page now.
9:28We've got that set up.
9:30Scroll down here, and when we enabled the date tools,
9:36date tools has a configuration page, which is the page where you can actually
9:40set up the date wizard.
9:42It also has a permissions page, so let's take a quick look at that
9:45and see what permissions we got.
9:47If we scroll up a little bit, we can see that date tools comes with permission to administer
9:53the date tools.
9:54Now date tools, lets us do some very powerful things.
9:57It lets us create new content types.
9:59It lets us add fields to those content types.
10:03So this is a permission that you'd want to restrict very carefully to just the highest level
10:12Then I can go back down here and click on the configure link
10:19and that takes me to the place where I can actually manage my date tools.
10:27The main thing that the date tools has is the date wizard.
10:31I'm just going to flip back and show you one more way that I can get there
10:33rather than going through the modules page, if I go back to the configuration page,
10:37and I scroll down, you can see that I've got a date API section
10:41of the configuration page, and I also have a link there to get to this date tools.
10:48So let's go ahead and use the date wizard to get us started real quickly.
10:53What it does, basically, is it says it's going to automatically create a content type,
10:58and then attach a date field to it and set it up in a good basic way,
11:05so you don't have to go through all of the individual steps of creating the content type
11:09and adding the field.
11:11If you have the calendar module enabled, it also is going to give you an option
11:14to create a calendar at the same time.
11:17We don't have the calendar enabled, and we'll be showing that kind of thing later.
11:23So right now, we're just going to create a date content type and a date field.
11:27If I scroll down, I can see that for the content type I can choose the content type name,
11:32and this is the machine-readable name and then the label,
11:35which is the human-readable name,
11:37and then a description, and in this case, we're not linking this to a calendar,
11:42so I'm just going to change this description a little bit.
11:47Then down here a little bit farther, we have the place where we can set up the date field
11:53and the date field name, and this is the machine-readable name for the date field
11:59that we're going to create in the label.
12:01Then I have an option of a text field or a select widget for the type of widget,
12:09and I would have other options if I had other modules enabled,
12:12which we'll demonstrate later.
12:14There's some advanced options.
12:16I can make some additional changes to time zone handling and granularity,
12:20and we're going to talk about all those options later,
12:23but for right now, we're just going to create something that uses the defaults.
12:29So you can see that what we ended up with is, we ended up with a content type called date.
12:34It has a title. It has a date field, and it has a description.
12:39Let's go ahead and just try adding some content to see what this is going to look like.
12:45So I've got a new content type, and this is my test date,
12:52and I can choose whether or not it's got an end date,
12:54and let's do 10:45 to 11:45 on April 3rd, and my description goes here.
13:08So I can put whatever into my description, and I save it.
13:12There we go!
13:14In just a couple of steps, I got to the point where I had a date.
13:19Now one thing looks a little bit funny, and that is my date is below the description,
13:24and in fact, I would have wanted that date to be above the description,
13:27so let's go back and see what happened there and fix it real quickly.
13:31So if I go on my structure to the content types area,
13:35I can see where my date content type is.
13:37There is a link here to the manage display for the date field,
13:42and you can see that it looks like the date is above the description,
13:46so it, in fact, is where it belongs, but it's not showing up right,
13:50and this is actually nothing to do with the date module.
13:53This is just a quirk in the way that this draggable table in the field UI works.
13:59All I have to do is move them and move them back just to trigger the fact
14:04that there's a change and save it.
14:06Now if I go back and take a look at that content that I just created,
14:10now I've got it where I want.
14:12The date is on top, and the description is below.
14:15Now the last thing that I want to do in this initial step to get started
14:19is I want to create some content.
14:20I'm going to create some views. I want to do some different things.
14:23It would be nice to have a lot of content that already has dates on it.
14:27So let's go try and do that.
14:30If I go back to modules, I previously downloaded the Devel module--D-E-V-E-L.
14:38The Devel module comes with something called Devel generate,
14:41which is a really nice tool for creating dummy content,
14:48just for cases like this.
14:50So I'm going to enable Devel generate, and it requires Devel,
14:53so I'm going to enable both of those, and I'm going to save that.
14:59If I go to the configuration area now, and I scroll down.
15:04I can see that I now have some options to generate content, menus, terms, users.
15:08I'm going to go ahead and generate some content, and I want to generate content
15:12of the type date, and I could choose to delete all content if I had some content in there.
15:19In fact, I created that one little dummy note, and I'm going to go ahead and delete that
15:24at the same time I create some new dummy content.
15:28I can choose how far back into the time the nodes should be created--
15:31or should be dated.
15:32 Now this does not have anything to do with the date field date.
15:37This is the creation date of the node, but it's nice when you get to things like views
15:42to have things scattered over a period of time.
15:45I'm going to go ahead and say--I'm going to go back a year.
15:50I'm just going to go ahead and generate,
15:53and it says I finished--I deleted the one node that I had previously created,
15:57and I created 15 new nodes, and if I go to find content,
16:02and I go take a look at one of them, I can see now I have dummy content,
16:06and my dummy content has dates on it.