You are here

function social_media_links_form in Social Media Links Block and Field 7

2 calls to social_media_links_form()
social_media_links_block_configure in ./social_media_links.module
Implements hook_block_configure().
social_media_links_widget_form in plugins/content_types/social_media_link_widget.inc
Callback for the edit form.

File

./social_media_links.module, line 79
Functions for the Social Media Links module.

Code

function social_media_links_form($values) {
  $form = array();

  // Platforms.
  $form['platforms'] = array(
    '#type' => 'fieldset',
    '#title' => t('Platforms'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
    '#theme' => 'social_media_links_platforms_table',
  );
  $platform_values = isset($values['platforms']) ? $values['platforms'] : array();
  $platforms = social_media_links_platforms();
  if (!empty($platform_values)) {

    // Combine the platforms with the weight value for sorting.
    foreach ($platforms as $key => $value) {
      if (isset($platform_values[$key]['weight'])) {
        $platforms[$key]['weight'] = $platform_values[$key]['weight'];
      }
    }
    uasort($platforms, 'drupal_sort_weight');
  }
  $i = -10;
  foreach ($platforms as $key => $value) {
    $form['platforms'][$key] = array(
      'platform_value' => array(
        '#type' => 'textfield',
        '#title' => $value['title'],
        '#title_display' => 'invisible',
        '#size' => 40,
        '#field_prefix' => $value['base url'],
        '#default_value' => isset($platform_values[$key]['platform_value']) ? $platform_values[$key]['platform_value'] : '',
      ),
      'weight' => array(
        '#type' => 'weight',
        '#title' => t('Weight'),
        '#title_display' => 'invisible',
        '#delta' => 10,
        '#default_value' => isset($platform_values[$key]['weight']) ? $platform_values[$key]['weight'] : $i + 1,
        '#attributes' => array(
          'class' => array(
            'weight',
          ),
        ),
      ),
    );
    $i++;
  }

  // Appearance.
  $form['appearance'] = array(
    '#type' => 'fieldset',
    '#title' => t('Appearance'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $appearance_values = isset($values['appearance']) ? $values['appearance'] : array();
  $form['appearance']['orientation'] = array(
    '#type' => 'select',
    '#title' => t('Orientation'),
    '#default_value' => isset($appearance_values['orientation']) ? $appearance_values['orientation'] : 'h',
    '#options' => array(
      'v' => t('vertical'),
      'h' => t('horizontal'),
    ),
  );
  $form['appearance']['show_name'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show name'),
    '#description' => t('Show the platform name next to the icon.'),
    '#default_value' => isset($appearance_values['show_name']) ? $appearance_values['show_name'] : 0,
  );

  // Link Attributes.
  $form['link_attributes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Link attributes'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $link_values = isset($values['link_attributes']) ? $values['link_attributes'] : array();
  $form['link_attributes']['target'] = array(
    '#type' => 'select',
    '#title' => t('Default target'),
    '#default_value' => isset($link_values['target']) ? $link_values['target'] : '<none>',
    '#options' => array(
      '<none>' => t('Remove target attribute'),
      '_blank' => t('Open in a new browser window or tab (_blank)'),
      '_self' => t('Open in the current window (_self)'),
      '_parent' => t('Open in the frame that is superior to the frame the link is in (_parent)'),
      '_top' => t('Cancel all frames and open in full browser window (_top)'),
    ),
  );
  $form['link_attributes']['rel'] = array(
    '#type' => 'select',
    '#title' => t('Default rel'),
    '#default_value' => isset($link_values['rel']) ? $link_values['rel'] : '<none>',
    '#options' => array(
      '<none>' => t('Remove rel attribute'),
      'nofollow' => t('Set nofollow'),
    ),
  );

  // Icon Sets.
  $form['icons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Icon Sets'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $options = social_media_links_iconsets_options();
  $form['icons']['icon_style'] = array(
    '#type' => 'select',
    '#title' => t('Icon Style'),
    '#default_value' => $values['icon_style'],
    '#options' => $options,
  );

  // Generate the icon set table.
  $header = array(
    array(
      'data' => t('Name'),
      'style' => 'width: 150px;',
    ),
    t('Sizes'),
    t('Icon examples and download instructions'),
  );
  $rows = array();
  $icons = social_media_links_iconsets();
  foreach ($icons as $iconset_name => $iconset) {
    if (isset($iconset['download url'])) {
      $name = '<strong>' . l($iconset['name'], $iconset['download url'], array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )) . '</strong>';
    }
    else {
      $name = '<strong>' . $iconset['name'] . '</strong>';
    }
    if (isset($iconset['publisher'])) {
      $name .= '<br />' . t('by') . ' ';
      if (isset($iconset['publisher url'])) {
        $name .= l($iconset['publisher'], $iconset['publisher url'], array(
          'attributes' => array(
            'target' => '_blank',
          ),
        ));
      }
      else {
        $name .= $iconset['publisher'];
      }
    }
    $row = array(
      $name,
      implode('<br />', $iconset['styles']),
    );
    if (!empty($iconset['path'])) {
      $row[] = _social_media_links_generate_example_table($platforms, $iconset);
    }
    else {
      $searchdirs = social_media_links_searchdirs($iconset_name);
      $str = '<strong>' . t('Not installed.') . '</strong><br />';
      $str .= t('To install: !download and install it into', array(
        '!download' => l(t('Download'), $iconset['download url'], array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
      ));
      $str .= ' <code> DRUPAL_ROOT/' . preg_replace('/,([^,]+) ?$/', " " . t('or') . " \$1", implode(', ', $searchdirs), 1) . '</code>.';
      if (isset($iconset['additional instructions'])) {
        $str .= ' ' . $iconset['additional instructions'];
      }
      $row[] = $str;
    }
    $rows[] = $row;
    $vars = array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'social-media-links-iconsets',
      ),
    );
    $form['icons']['installed'] = array(
      '#markup' => theme('table', $vars),
    );
  }
  return $form;
}