You are here

function yashare_widget_pre_render in Yandex.Share 7.2

Pre-render callback for the 'yashare_widget' element. See http://api.yandex.ru/share/doc/dg/concepts/share-button-ov.xml

1 string reference to 'yashare_widget_pre_render'
yashare_element_info in ./yashare.module
Implements hook_element_info().

File

./yashare.module, line 413

Code

function yashare_widget_pre_render($element) {
  $path = drupal_get_path('module', 'yashare');

  // Adding REQUEST_TIME to the id to make it generally unique.
  // @see https://www.drupal.org/node/2472511
  $element['#id'] = drupal_html_id($element['#id'] . '-' . REQUEST_TIME);
  $element['#theme'] = 'yashare_widget_' . $element['#init_type'];
  if (!isset($element['#quickservices'])) {
    $element['#quickservices'] = array_values(yashare_get_enabled_services('block', $element['#yashare_theme']));
  }
  if (!isset($element['#popup_services'])) {
    $element['#popup_services'] = array_values(yashare_get_enabled_services('popup', $element['#yashare_theme']));
  }
  $element['#attached']['js'][$path . '/js/yashare.async.js'] = array(
    'weight' => 0,
  );

  // For the automatic initialization type we need just one JS file.
  if ($element['#init_type'] == 'automatic') {
    $element['#attached']['js'][$path . '/js/yashare.automatic.js'] = array(
      'weight' => 10,
    );
    return $element;
  }

  // General parameters.
  $params = array(
    'element' => $element['#id'],
    'l10n' => $element['#l10n'],
    'theme' => $element['#yashare_theme'],
  );

  // Link parameters.
  if ($element['#link']) {
    $params['link'] = $element['#link'];
  }
  if ($element['#title']) {
    $params['title'] = check_plain($element['#title'] . ' | ' . variable_get('site_name', 'Drupal'));
  }
  if ($element['#description']) {
    $params['description'] = check_plain($element['#description']);
  }
  if ($element['#image']) {
    $params['image'] = $element['#image'];
  }

  // Block parameters.
  $params['elementStyle'] = array(
    'text' => $element['#block_title'],
    'type' => $element['#yashare_type'],
    'border' => $element['#border'],
    'linkUnderline' => $element['#linkunderline'],
    'linkIcon' => $element['#linkicon'],
    'quickServices' => $element['#quickservices'],
  );

  // Popup parameters.
  $params['popupStyle'] = array(
    'blocks' => $element['#popup_title'] ? array(
      $element['#popup_title'] => $element['#popup_services'],
    ) : $element['#popup_services'],
    'copyPasteField' => $element['#copypastefield'],
  );
  if ($element['#vdirection']) {
    $params['popupStyle']['vDirection'] = $element['#vdirection'];
  }
  if ($element['#codeforblog'] && isset($params['title']) && isset($params['link'])) {
    $params['popupStyle']['codeForBlog'] = l($params['title'], $params['link'], array(
      'attributes' => array(
        'title' => $params['title'],
        'target' => '_blank',
      ),
    ));
  }
  $element['#attached']['js'][$path . '/js/yashare.standard.js'] = array(
    'weight' => 10,
  );
  $element['#attached']['js'][] = array(
    'data' => array(
      'yashare' => array(
        $element['#id'] => $params,
      ),
    ),
    'type' => 'setting',
  );
  return $element;
}