Drupal 7

Path to theme, module, or library - drupal_get_path ()

There are many instances where you need to get the path to a theme, a module or a library. Here are some possible methods:

menu get object - to load the current entity

One option for loading a node or a term page is to use entity load.
Another option that works for loading the current node or term page you are on is to use menu_get_object()

Deleted Field Tables keep multiplying

When you delete a field, if there is data in it, Drupal does a bit of a two-step shuffle to avoid locking the tables while it gets rid of them, so it moves them to other tables so it can go through them one at a time when cron runs.

Sometimes this process does not clean itself up. You will notice It by seeing the number of tables in your DB grow and the DB will contain lots of
tables like this

WARNING: Editing Webform form settings can cause custom alias to revert to pattern

THere is a bug in pathauto right now that causes nodes to lose track of whether they should use the pathauto alias pattern or an overridden value.

It is being worked on... but not very rapidly http://drupal.org/node/936222

Drupal Add CSS

The Drupal Add CSS function http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_a...
has the ability to group css by weight, but it gives the appearance that you are limited to three groups.
'group': A number identifying the group in which to add the stylesheet. Available constants are:
CSS_SYSTEM: Any system-layer CSS.
CSS_DEFAULT: (default) Any module-layer CSS.
CSS_THEME: Any theme-layer CSS.

Drupal header logo SEO markup

The default Drupal header markup for the site logo is horrible SEO... it just plain misses a great opportunity.
The original code , usually in the page.tpl.php looks like this:

<a href="/" title="Home" rel="home" id="logo">
          <img src="http://web-dev.wirt.us/sites/web-dev.wirt.us//files/logo_0.png" alt="Home" />

Improved version of the code:

Drupal: Check to see if a file or directory exists

Sometimes you want to see if a file or directory in the managed file system exists and base your logic off its existence.
Example: wanting to know if the directory /sites/web-dev.swirt.us/files/jqueryui_theme/redmond/ exists before including it
Use is_dir() http://php.net/manual/en/function.is-dir.php
The trick is to add the public:// stream wrapper

Alt attributes on links (just say NO)

I have run into many instances in our sites, especially on grid templates where alt attributes are being set in a link option. This should not be happening. There is NO alt attribute for anchor tags. Only img tags have alt attributes and they should/must be used.

This is an example of BAD code [The link has an alt, but the img does not.]

Viewing and editing a field collection item separate from the node where it is used.

Field collections actually can be pathed to for editing or deleting.  This is useful in cases where it has become detached from the node it was created with.

The path is made up of /field-collection/{field collection field name}

You can find the field collection field name by looking at the fields on the content type.

Drupal /node behavior

Drupal's default home page is a preview of nodes. We never use it. We always put in a custom home page. The problem is, "www.thesite.com/node" still exists and will return a list of recent nodes. Usually it looks broken and is completely useless. To keep it from being accessed by humans or spiders do the following

Create a 301 redirect from node to <front> by going here

From:  node

To: <front>


Subscribe to RSS - Drupal 7