user_category_edit_form_from_user.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an relationship handler for term from node.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t('User category edit form from user'),
  12. 'keyword' => 'user_category_form',
  13. 'description' => t('Adds user category edit form from a user context.'),
  14. 'required context' => new ctools_context_required(t('User'), 'user'),
  15. 'context' => 'ctools_user_category_edit_form_from_user_context',
  16. 'edit form' => 'ctools_user_category_edit_form_from_user_settings_form',
  17. 'defaults' => array('category' => NULL),
  18. );
  19. /**
  20. * Return a new context based on an existing context.
  21. */
  22. function ctools_user_category_edit_form_from_user_context($context, $conf) {
  23. if (empty($context->data)) {
  24. return ctools_context_create_empty('user_edit_form', NULL);
  25. }
  26. if(!empty($conf['category'])) {
  27. return ctools_context_create('user_edit_form', $context->data, array('category' => $conf['category']));
  28. }
  29. if (isset($context->data->user_category)) {
  30. return ctools_context_create('user_edit_form', $context->data, array('category' => $context->data->user_category));
  31. }
  32. return ctools_context_create('user_edit_form', $context->data);
  33. }
  34. /**
  35. * Settings form for the relationship.
  36. */
  37. function ctools_user_category_edit_form_from_user_settings_form($form, &$form_state) {
  38. $conf = $form_state['conf'];
  39. $categories = _user_categories();
  40. $options = array();
  41. foreach($categories as $category) {
  42. $options[$category['name']] = $category['title'];
  43. }
  44. $form['category'] = array(
  45. '#type' => 'select',
  46. '#title' => t('Category'),
  47. '#options' => $options,
  48. '#default_value' => isset($conf['category']) ? $conf['category'] : NULL,
  49. '#empty_option' => 'Default',
  50. );
  51. return $form;
  52. }