From 915ab88083ece4b087fee2b93a1e7307aad574ff Mon Sep 17 00:00:00 2001
From: Darren Shelley <darren.shelley@gmail.com>
Date: Wed, 24 Apr 2013 10:56:06 +0100
Subject: [PATCH] Issue #1978510 by Darren Shelley: Simplify node form alter
 using hook_form_BASE_FORM_ID_alter().

---
 page_title.module |   52 ++++++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 28 deletions(-)

diff --git a/page_title.module b/page_title.module
index 321a57c..26f07f7 100644
--- a/page_title.module
+++ b/page_title.module
@@ -184,38 +184,34 @@ function page_title_node_type($op, $info) {
 
 
 /**
- * Implement hook_form_alter().
- * (cant use hook_form_FORM_ID_alter(). here as the form ID changes from node to node)
+ * Implement hook_form_BASE_FORM_ID_alter().
  */
-function page_title_form_alter(&$form, $form_state, $form_id) {
+function page_title_form_node_form_alter(&$form, $form_state, $form_id) {
   // If we dont have permission to set the title then we need to abort this alter now!
   if (!user_access('set page title')) return;
 
-  // If we're editing a node...
-  if (!empty($form['#node_edit_form'])) {
-    // ... and the show field is enabled for this node type
-    if (variable_get('page_title_type_' . $form['type']['#value'] . '_showfield', 0)) {
-      $page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : NULL;
-      $form['page_title'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Page title settings'),
-        '#collapsible' => TRUE,
-        '#collapsed' => empty($page_title),
-        '#group' => 'additional_settings',
-        '#weight' => 35,
-        '#attached' => array(
-          'js' => array(drupal_get_path('module', 'page_title') . '/page_title.js'),
-        ),
-      );
-      $form['page_title']['page_title'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Page title'),
-        '#description' => t('Provide a description of this node to appear in the &lt;title&gt; tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
-        '#default_value' => $page_title,
-        '#size' => 60,
-        '#maxlength' => 255,
-      );
-    }
+  // If the show field is enabled for this node type
+  if (variable_get('page_title_type_' . $form['type']['#value'] . '_showfield', 0)) {
+    $page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : NULL;
+    $form['page_title'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Page title settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => empty($page_title),
+      '#group' => 'additional_settings',
+      '#weight' => 35,
+      '#attached' => array(
+        'js' => array(drupal_get_path('module', 'page_title') . '/page_title.js'),
+      ),
+    );
+    $form['page_title']['page_title'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Page title'),
+      '#description' => t('Provide a description of this node to appear in the &lt;title&gt; tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
+      '#default_value' => $page_title,
+      '#size' => 60,
+      '#maxlength' => 255,
+    );
   }
 }
 
-- 
1.7.9.5

