diff --git a/README.txt b/README.txt index dde38f6..efff179 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,10 @@ 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. + \ No newline at end of file diff --git a/plugins/content_types/reply_add_form.inc b/plugins/content_types/reply_add_form.inc index e69de29..065e189 100644 --- a/plugins/content_types/reply_add_form.inc +++ b/plugins/content_types/reply_add_form.inc @@ -0,0 +1,124 @@ + 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 = ''; + $output = drupal_get_form('reply_add_form', $entity->identifier(), $reply_field_instance['id'], FALSE); + $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'); +} + +/** + * Display the administrative information for reply_add_form. + */ +function reply_add_form_content_type_admin_info($subtype, $conf) { +} + +/** + * 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 field instances for the given entity, and add the 'reply' type fields + // as options. + $entity_fields = field_info_instances($entity_type, $entity_type); + foreach ($entity_fields as $field) { + $field_info = field_info_field($field['field_name']); + if ($field_info['type'] == 'reply') { + $options[$field['field_name']] = $field['label'] . ' (' . $field['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) { + foreach ($form_state['values'] as $k => $v) { + if (!empty($form_state['values'][$k])) { + $form_state['conf'][$k] = $form_state['values'][$k]; + } + } +} + +/** + * 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); +} diff --git a/reply.module b/reply.module index 7fe7ed7..2090d2d 100644 --- a/reply.module +++ b/reply.module @@ -1866,3 +1866,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; + } +}