From 369a57d41ae2d3ddcff8387b8fcb475707e9fc1f Mon Sep 17 00:00:00 2001
From: Carwin Young <carwinyoung@gmail.com>
Date: Thu, 18 Apr 2013 10:22:02 -0500
Subject: [PATCH] Issue #1959830 by carwin: made metatags available to node
 edit forms via Panels.

---
 metatag.module                                   | 12 +++++
 plugins/content_types/metatag_node_form_pane.inc | 58 ++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
 create mode 100644 plugins/content_types/metatag_node_form_pane.inc

diff --git a/metatag.module b/metatag.module
index 8b4d9fe..970a84a 100644
--- a/metatag.module
+++ b/metatag.module
@@ -54,6 +54,18 @@ function metatag_ctools_plugin_api($owner, $api) {
 }
 
 /**
+ * Implements hook_ctools_plugin_directory().
+ *
+ * Tell ctools to look in plugins/content_types when it's looking for
+ * panels/page manager content types.
+ */
+function metatag_ctools_plugin_directory($owner, $plugin_type) {
+  if ($owner == 'ctools' && $plugin_type == 'content_types') {
+    return 'plugins/content_types';
+  }
+}
+
+/**
  * Implements hook_hook_info().
  */
 function metatag_hook_info() {
diff --git a/plugins/content_types/metatag_node_form_pane.inc b/plugins/content_types/metatag_node_form_pane.inc
new file mode 100644
index 0000000..898d262
--- /dev/null
+++ b/plugins/content_types/metatag_node_form_pane.inc
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * @file
+ * Handle rendering Meta tags fields as a Panels pane.
+ */
+
+$ctools_path = drupal_get_path('module', 'ctools');
+
+$plugin = array(
+  'single' => TRUE,
+  'category' => array(t('Form')),
+  'edit form' => 'metatag_node_form_pane_node_form_menu_content_type_edit_form',
+  'render callback' => 'metatag_node_form_pane_content_type_render',
+  'title' => t('Metatags'),
+  'icon' => $ctools_path . '/plugins/content_types/node_form/icon_node_form.png',
+  'description' => t('Add meta tags to the node.'),
+  'required context' => new ctools_context_required(t('Form'), 'node_form'),
+  'category' => t('Form'),
+);
+
+/**
+ * Run-time rendering of the body of the block pane (content type).
+ */
+function metatag_node_form_pane_content_type_render($subtype, $conf, $panel_arguments, &$context) {
+  $block = new stdClass();
+  $block->module = t('node_form');
+
+  $block->title = t('Meta tags');
+  $block->delta = 'metatags-options';
+
+  if (isset($context->form)) {
+    if (isset($context->form['metatags'])) {
+      $block->content['metatags'] = $context->form['metatags'];
+      unset($block->content['metatags']['#pre_render']);
+      unset($block->content['metatags']['#theme_wrappers']);
+      $block->content['metatags']['#type'] = '';
+      // From the ctools example:
+      // Set access to false on the original rather than removing so that
+      // vertical tabs doesn't clone it.
+      $context->form['metatags']['#access'] = FALSE;
+    }
+  }
+  else {
+    // From the ctools example:
+    $block->content = t('Metatags');
+  }
+  return $block;
+}
+
+/**
+ * Edit form callback for this content type.
+ */
+function metatag_node_form_pane_node_form_menu_content_type_edit_form($form, &$form_state) {
+  // The form in page manager UI for configuring this pane when used.
+  // Just do default stuff.
+  return $form;
+}
-- 
1.8.2

