Using Namespaces in Drupal 7

So in my adventure of trying to figure out how to implement object orientation into Drupal 7 (preparing for the imminent move to Drupal 8), I've come to the point of trying to figure out namespaces. Now, the last time I used a legitimate namespace was about 7 years ago in my freshman C++ course (cstdlib anyone?), so I'm putting on my nostalgia goggles for this one. I started my project by creating a class ClassName.php inside of a folder ('cause I am organized like that), then, in standard Drupal 7 fashion, I included it in the .info file, like so:

I proceeded to call my new class in my code elsewhere; $thing = new ClassName();. It worked! All was right in my world. Then I decided, "hmm... You know since I'm so new at this, I should have a friend who knows a little more about OO in PHP look at this and tell me if things look right!". Sure enough, I get approval from my friend. "Dude, your private and public functions look great and your module is pretty awesome!", he says. So I'm on top of the world at that moment, i'm learning new stuff and the stuff is working. Then he drops the bomb, "If you really want to get into good OO habits for PHP, you should start using namespaces." Namespaces sound pretty hacker to me, i'm in.

Tags: 
Projects
drupal

Gist: Why can't you highlight syntax correctly?

Why is it when I select 'PHP' for syntax highlighting on their ACE Editor, it just reverts to plain text upon save? Why do you do this to me, github? Adding php tags doesn't seem to help, either.

EDIT: Apparently you have to give it a .php extension in the filename field. If it's a code snippet, why does it need a filename at all?

They moved my dirt.




Then they filled it with some concrete.

I'm building a house!

I'm pretty excited, but honestly it all seems very surreal. The closing date feels like it will never come because I never really pictured myself as a home-owner... despite knowing that I would eventually be some day. 'Guess "someday" is finally on its way! My wife and I have been blessed with enough to be able to do this; we are not only buying our first house, we are custom building it. Now that's an incredible thought.


Of course, the picture above is merely an example rendering and doesn't reflect our color choices in brick/shingles/etc. We are looking at having it completed some time in September of this year, just in time for my 27th birthday. We've chosen a location on the growing southwest side of Lubbock... and when I say 'growing', I mean that Lubbock is talking about building another MEGA loop around the current loop (inner and outer loops) and annexing a huge area to the southwest of the current city limits. Anyhow, here is a layout. I'll be taking tons of pictures once the construction starts. I can't wait!

Date Popup Frustrations

Firstly, let me preface this by saying thank you to the great contributors who have written modules like Date Popup and many others that I use on a daily basis. That said, why can't you get past 99% functionality on anything? My frustration comes from the fact that you can't, by default/easily, allow the Date [Popup] field to be blank. What if it's not a required field and can be blank? For instance, i'm writing this application here where 'Fit Date' is a field that is purposefully NOT set upon creation of the content, but rather set later on down the road. Now obviously I've figured out a way to do this, as you can see from the image below... here is the short of the headache I endured to make it happen.

$form['test_fieldset']['fit_date'] = array(
    '#type' => 'date_popup',
    '#title' => "Fit Date",
    '#format' => "Y-m-d",
    '#default_value' => '0000-00-00',
    '#date_type' => DATE_DATETIME,
    '#date_year_range' => '-0:+0',
);

Tags: 
drupal