Drupal CMS

Moving a site from one account to another in Pantheon

Today I learned there's no automatic way to move a project from one account within Pantheon to another.  But the manual way is super simple.

Step 1: In the "from" account, create a backup of the site.  It should look something like this:

Step 2: In the "to" account, choose "Import a Site" and then choose "provide separate code, files, and databasde archives":


Step 3: Foreach of code, database, and files, in the "from" account, click the "download" link and copy the "temporary link" it gives you:

Then paste that link in the corresponding field in the "To" account:


 

Step 4: Push the red, jolly, candy-like button at the bottom and you're on your way.

Protip:  When they say temporary links, they mean temporary.  Don't start copying your links until all 3 of your archives have been created.  The links are only good for a minute or two.

 

Prevent "AHAH the Right Way" in Drupal from Breaking with Validation

So there has been a lot of blogging and documentation in the past about the "right" way to do AHAH in Drupal. I think these people make excellent points, provide good documentation, and are pushing these types of dynamic interactions in Drupal in the right direction. I think a lot what's out there about this "right way" to do AHAH in Drupal misses some critical issues, though. Maybe someone else has blogged about it already, but I'll share one pitfall that I learned to avoid while doing AHAH.

Specifically, if you have a form using AHAH, there are a series of events that can lead to the form breaking completely:

  1. Load form
  2. Activate AHAH element (which calls AHAH callback, rebuilds form, then recaches form)
  3. Submit form with an error
  4. Validation reloads the page with a re-rendered copy of the form and errors
  5. Fix form errors, and submit form
  6. BOOM!

What happened? The form submits and you probably get a load of JSON output, and your browser's URL is at the AHAH callback location. WHAT?

So, what happened is this: during the AHAH callback, the form is rebuilt. However, during the form rebuild, the #action element on the form is set to the default... which is the current request URI, which will be the path to the AHAH callback. This is bad, because now when you have a form validation error and the form is re-rendered in its entirety (as opposed to just using a section of re-rendered form as during the AHAH callback), the form now has its #action property set to the path of the AHAH callback.

That is bad. There have been mentions of how to fix it, but here is how I did it:

So there is this semi-utility-function-like block of code that AHAH the "right way" depends on existing in the AHAH callback, which looks something like this:

// From http://drupal.org/node/331941
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

That final call to drupal_rebuild_form() does a couple things: it rebuilds the form array, and it caches the result. This means that we can't just change the $form variable here after our call to drupal_rebuild_form() -- we need to make our form generator function smart! To do that, I made an important change to the above code:

// From http://drupal.org/node/331941
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
$form['#programmed'] = $form['#redirect'] = FALSE;
// Stash original form action to avoid overwriting with drupal_rebuild_form().
$form_state['action'] = $form['#action'];
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

Notice that I stashed the form's original #action property (as loaded from the previously-cached version of the form) in the $form_state variable. Then, when drupal_rebuild_form() goes to work, this little bit of code in my form function makes sure that my #action is correct through AHAH+Validation:

$form['#cache'] = TRUE; // Make sure the form is cached.

// Pull the correct action out of form_state if it's there to avoid AHAH+Validation action-rewrite.
if (isset($form_state['action'])) {
  $form['#action'] = $form_state['action'];
}

Now when the form is rebuilt during my AHAH call, it explicitly sets the #action property, which prevents the #action overwrite when drupal_prepare_form() (which is called by drupal_rebuild_form()) adds the result of _element_info('form') to the form (adding an array to another will add keys from the second array to the first, but not overwrite keys in the first that are also present in the second -- so $form['#action'] being present already prevents it from being overwritten).

Originally posted on my personal blog, here.

Tags:

Drupal in the Real World: PANMA Event on 9/28

Getting to know Drupal
“Come for the Code, Stay for the Community” is the newly adopted tagline for the Drupal project. At this session we’ll give you an introduction to both the code that is driving the extremely fast adoption of Drupal, as well as the community that makes, builds and supports this truly Free and Open Source Software project (meaning: unlike projects like WordPress, Alfresco, or MySQL, no company owns Drupal).

What we’ll cover:
Some of the main reasons that organizations and companies are adopting Drupal, including the module and theme systems, robust content creation and organization features, tight integration with most popular APIs, its user & role system, content permissions, flexible workflow, etc.

- What’s new in Drupal 7, including the Database Abstraction Layer that has opened the door for running Drupal on Oracle, MS SQL Server, Casandra, etc, to improved core media handling, the move from ‘nodes’ to ‘entities’, fields in core, and more.

- Acquia’s Drupal Gardens, a hosted ‘Software as a Service’ version of Drupal 7, meant to compete with WordPress.com and other hosted website options.

- The Drupal community. Drupal owes much of its growth to the early adoption of the platform by community/political organizers, and these same people use their online organizing skills to enable the Drupal community to scale faster and better than most other Open Source projects. We’ll look at where the community works/communicates, how it operates, and what makes it tick (hint: talk is silver, code/work is gold).

Alex Urevick-Ackelsberg is a Partner and Business Lead at Zivtech, LLC. Zivtech is an Open Source Web Development Shop located in Philadelphia, PA that specializes in building powerful and scalable Web Applications and Enterprise Content Management Systems

Drupal in the Real World
Following a look at the technology and community behind Drupal, we’ll share what it’s like to build a site with the platform today. We’ll look at how to plan a Drupal-based site, how to document the information architecture requirements, how to choose the right modules for the job, and how to solve common site-building challenges without hacking.

We’ll leave you with an amusing tour of 5 things you *can* do with Drupal, but *shouldn’t.* *Ever*.

Nathan Gasser is founder and president of Rock River Star, an internet consulting and development company focussed on implementing open source web and social media solutions for non-profit, higher education, and corporate clients.

Pizza & light refreshments will be provided by PANMA. Doors open at 5:30pm, event runs 6:00 – 8:00pm. The cost is free.

 

RSVP at http://bit.ly/dyUKlu

AddtoAny Replaces Share This as Default Module for Service Links

After learning of a recent bug in the production release of the ShareThis module, I've started to switch clients to the AddtoAny module. They provide very similar functions, but one is broken.  That's right, one day ShareThis just stopped working. There are a lot of external JS and CSS files that it uses. The word is one of the JS files is broken and causes a bug on the mouseover or popup div. The popup window works, but who wants one of those?  Users want popup divs.

 

After much debugging, I went to the interwebs and found a thread on the issue I have. No one had a fix for the production version of the module, but there was a solution -- move to AddtoAny. So I tried it and it works like a dream. It doesn't let me type in a text title for the button, but does let me use a graphic from my local machine. As long as we don't need to change the label of the button, this doesn't involve any extra work.

 

Tags: