social_media_link_widget.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @file
  4. * Defines the social media links widget for panels.
  5. */
  6. $plugin = array(
  7. 'title' => t('Social Media Links'),
  8. 'description' => t('Create a Social Media Links widget.'),
  9. 'category' => array('widgets', 0),
  10. 'single' => FALSE,
  11. 'admin info' => 'social_media_links_widget_admin_info',
  12. 'edit form' => 'social_media_links_widget_form',
  13. 'render callback' => 'social_media_links_widget_render',
  14. );
  15. /**
  16. * Callback to provide administrative info (the preview in panels when building a panel).
  17. */
  18. function social_media_links_widget_admin_info($subtype, $conf, $context = NULL) {
  19. if (!empty($conf)) {
  20. $platform_infos = social_media_links_platforms();
  21. $active_platforms = array();
  22. foreach ($conf['platforms'] as $name => $platform) {
  23. if (!empty($platform['platform_value'])) {
  24. $active_platforms[] = $platform_infos[$name]['title'];
  25. }
  26. }
  27. $content = t('Activated Platforms: @platforms', array('@platforms' => implode(', ', $active_platforms)));
  28. $content .= '<br />' . t('Iconset: @iconset', array('@iconset' => $conf['icon_style']));
  29. $block = new stdClass();
  30. $block->title = $conf['override_title'] ? $conf['override_title_text'] : t('Follow Us');
  31. $block->content = $content;
  32. return $block;
  33. }
  34. }
  35. /**
  36. * Callback for the edit form.
  37. */
  38. function social_media_links_widget_form($form, &$form_state) {
  39. $form += social_media_links_form($form_state['conf']);
  40. return $form;
  41. }
  42. /**
  43. * Submit callback for the edit form.
  44. */
  45. function social_media_links_widget_form_submit($form, &$form_state) {
  46. foreach (element_children($form) as $key) {
  47. if (isset($form_state['values'][$key])) {
  48. $form_state['conf'][$key] = $form_state['values'][$key];
  49. }
  50. }
  51. if (isset($form_state['values']['icon_style'])) {
  52. $form_state['conf']['icon_style'] = $form_state['values']['icon_style'];
  53. }
  54. }
  55. function social_media_links_widget_render($subtype, $conf, $panel_args) {
  56. $block = new stdClass();
  57. $platforms = _social_media_links_cleanup_platforms($conf['platforms']);
  58. $content = array(
  59. '#theme' => 'social_media_links_platforms',
  60. '#platform_values' => $platforms,
  61. '#icon_style' => $conf['icon_style'],
  62. '#appearance' => $conf['appearance'],
  63. '#link_attributes' => $conf['link_attributes'],
  64. '#attributes' => array(
  65. 'class' => array('social-media-links', 'platforms'),
  66. ),
  67. );
  68. // Add css to the block.
  69. $content['#attached']['css'][] = drupal_get_path('module', 'social_media_links') . '/social_media_links.css';
  70. $block->title = $conf['override_title'] ? $conf['override_title_text'] : t('Follow Us');
  71. $block->content = $content;
  72. return $block;
  73. }