diff --git a/README.txt b/README.txt
index dde38f6..62e334b 100644
--- a/README.txt
+++ b/README.txt
@@ -21,7 +21,7 @@ Replies from users are administered in a content tab (similar to the existing Co
Frequently Asked Questions:
Q) How can I show author names on replies?
-A) Override reply.tpl.php with a version that outputs $username, e.g.
+A) Override reply.tpl.php with a version that outputs $username, e.g.
@@ -39,3 +39,9 @@ Q) Is there an easy way to return the reply count for a particular entity the re
A) You can do the following:
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
$count = count(reply_get_entity($entity_id, $entity_type, $instance['id']));
+
+Q) Is there any panels integration in place?
+A) Yes, there's a "Reply - Add form" content_type plugin under the 'Reply' category (inside the "add content" popup
+ of the Panels UI popup". It requires an entity context, but due to how contexts work, you can select any existing
+ context for the panel page being edited. Make sure the context chosen is one that return a loaded entity from the
+ system.
diff --git a/plugins/content_types/reply_add_form.inc b/plugins/content_types/reply_add_form.inc
new file mode 100644
index 0000000..673a35d
--- /dev/null
+++ b/plugins/content_types/reply_add_form.inc
@@ -0,0 +1,134 @@
+ TRUE,
+ 'title' => t('Reply - Add form'),
+ 'description' => t('Form to add a new reply to an Entity'),
+ 'category' => t('Reply'),
+ 'defaults' => array(),
+ 'render callback' => 'reply_add_form_content_type_render',
+ 'edit form' => array(
+ 'reply_add_form_select_entity_type' => t('Reply form - Entity Type'),
+ 'reply_add_form_select_reply_field' => t('Reply form - Reply Field'),
+ ),
+ 'required context' => array(
+ new ctools_context_required(t('Entity being viewed'), 'any'),
+ ),
+);
+
+/**
+ * Output function for the 'reply_add_form' content type.
+ */
+function reply_add_form_content_type_render($subtype, $conf, $panel_args, $context) {
+ // If there's no context, return nothing.
+ if (!$context[0]->data) {
+ return NULL;
+ }
+ $entity = $context[0]->data;
+ $reply_field_instance = field_info_instance($conf['reply_entity_type'], $conf['reply_field'], $conf['reply_entity_type']);
+
+ $block = new stdClass();
+ $block->title = '';
+ $form_options = array(
+ 'entity_id' => $entity->identifier(),
+ 'instance_id' => $reply_field_instance['id'],
+ );
+ $output = drupal_get_form('reply_form', (object) $form_options);
+ $block->content = array(
+ '#markup' => drupal_render($output),
+ );
+ return $block;
+}
+
+/**
+ * Returns the administrative title for reply_add_form.
+ */
+function reply_add_form_content_type_admin_title($subtype, $conf) {
+ return t('Reply - Add form');
+}
+
+/**
+ * Returns an edit form for custom type settings.
+ */
+function reply_add_form_select_entity_type($form, &$form_state) {
+ $entities = entity_get_info();
+ $options = array();
+
+ // Get all existing entities.
+ foreach ($entities as $entity_type => $entity) {
+ $options[$entity_type] = $entity['label'];
+ }
+
+ $form['config']['reply_entity_type'] = array(
+ '#type' => 'select',
+ '#title' => t('Entity Type'),
+ '#options' => $options,
+ '#default_value' => isset($form_state['conf']['reply_entity_type']) ? $form_state['conf']['reply_entity_type'] : NULL,
+ );
+ return $form;
+}
+
+/**
+ * Returns an edit form for custom type settings.
+ */
+function reply_add_form_select_reply_field($form, &$form_state) {
+ $options = array();
+ // Get entity type chosen in previous step.
+ $entity_type = $form_state['conf']['reply_entity_type'];
+
+ // Get all the field instances for the given entity type, and add the 'reply'
+ // ones as options.
+ $field_map = field_info_field_map();
+ $entity_fields = field_info_instances($entity_type, $entity_type);
+ $reply_fields = array_filter($field_map, '_reply_add_form_filter_reply_fields');
+
+ foreach ($entity_fields as $field_name => $field) {
+ if (isset($reply_fields[$field_name])) {
+ $options[$field['field_name']] = $field['label'] . ' (' . $field_name .')';
+ }
+ }
+
+ $form['config']['reply_field'] = array(
+ '#type' => 'select',
+ '#title' => t('Reply field'),
+ '#options' => $options,
+ '#default_value' => isset($form_state['conf']['reply_field']) ? $form_state['conf']['reply_field'] : NULL,
+ );
+ return $form;
+}
+
+/**
+ * Submit handler for the custom type settings form.
+ */
+function reply_add_form_select_entity_type_submit($form, &$form_state) {
+ $form_state['conf'] = array_merge($form_state['conf'], array_filter($form_state['values']));
+}
+
+/**
+ * Submit handler for the custom type settings form.
+ */
+function reply_add_form_select_reply_field_submit($form, &$form_state) {
+ reply_add_form_select_entity_type_submit($form, $form_state);
+}
+
+/**
+ * Returns whether a field is of 'reply' type.
+ *
+ * @param array $field
+ * An array with field data, as returned by field_info_field_map().
+ *
+ * @return bool
+ * TRUE, if the field is a 'reply' type field, FALSE otherwise.
+ */
+function _reply_add_form_filter_reply_fields($field) {
+ return ($field['type'] == 'reply');
+}
diff --git a/reply.module b/reply.module
index 8203df0..ec9f1c1 100644
--- a/reply.module
+++ b/reply.module
@@ -1721,3 +1721,12 @@ function _reply_get_login_url($destination) {
function _reply_get_register_url($destination) {
return url('user/register', array('query' => $destination));
}
+
+/**
+ * Implements hook_ctools_plugin_directory()
+ */
+function reply_ctools_plugin_directory($module, $plugin) {
+ if ($module == 'ctools') {
+ return 'plugins/' . $plugin;
+ }
+}