/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { $settings = $this->getSettings(); $markup = AddThis::getInstance()->getBasicToolboxMarkup($settings); return array('#markup' => $markup); }
/** * Returns rendered markup for the BasicToolbox display. This will be called * from both the Field and Block render functions. * @param $settings * @return null */ function getBasicToolboxMarkup($settings) { $element = array('#type' => 'addthis_wrapper', '#tag' => 'div', '#attributes' => array('class' => array('addthis_toolbox', 'addthis_default_style', $settings['buttons_size'] == AddThis::CSS_32x32 ? AddThis::CSS_32x32 : NULL, $settings['extra_css']))); // Add the widget script. $script_manager = AddThisScriptManager::getInstance(); $script_manager->attachJsToElement($element); $services = trim($settings['share_services']); $services = str_replace(' ', '', $services); $services = explode(',', $services); $items = array(); // All service elements $items = array(); foreach ($services as $service) { $items[$service] = array('#type' => 'addthis_element', '#tag' => 'a', '#value' => '', '#attributes' => array('href' => AddThis::getInstance()->getBaseBookmarkUrl(), 'class' => array('addthis_button_' . $service)), '#addthis_service' => $service); // Add individual counters. if (strpos($service, 'counter_') === 0) { $items[$service]['#attributes']['class'] = array("addthis_{$service}"); } // Basic implementations of bubble counter orientation. // @todo Figure all the bubbles out and add them. // Still missing: tweetme, hyves and stubleupon, google_plusone_badge. // $orientation = $settings['counter_orientation'] == 'horizontal' ? TRUE : FALSE; switch ($service) { case 'linkedin_counter': $items[$service]['#attributes'] += array('li:counter' => $orientation ? '' : 'top'); break; case 'facebook_like': $items[$service]['#attributes'] += array('fb:like:layout' => $orientation ? 'button_count' : 'box_count'); break; case 'facebook_share': $items[$service]['#attributes'] += array('fb:share:layout' => $orientation ? 'button_count' : 'box_count'); break; case 'google_plusone': $items[$service]['#attributes'] += array('g:plusone:size' => $orientation ? 'standard' : 'tall'); break; case 'tweet': $items[$service]['#attributes'] += array('tw:count' => $orientation ? 'horizontal' : 'vertical', 'tw:via' => AddThis::getInstance()->getTwitterVia()); break; case 'bubble_style': $items[$service]['#attributes']['class'] = array('addthis_counter', 'addthis_bubble_style'); break; case 'pill_style': $items[$service]['#attributes']['class'] = array('addthis_counter', 'addthis_pill_style'); break; } } $element += $items; return render($element); }
/** * {@inheritdoc} */ public function build() { $config = $this->configuration; switch ($config['type']) { case 'addthis_basic_button': $markup = AddThis::getInstance()->getBasicButtonMarkup($config['basic_button']); break; case 'addthis_basic_toolbox': $markup = AddThis::getInstance()->getBasicToolboxMarkup($config['basic_toolbox']); break; default: $markup = ''; break; } return array('#markup' => $markup); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('addthis.settings'); //Add our library to the settings form to add in custom CSS. $form['#attached']['library'][] = 'addthis/addthis.admin'; // Visual settings. $form['details_compact_menu'] = array('#type' => 'details', '#title' => t('Compact menu'), '#open' => TRUE, '#description' => '<p>' . t('Configure the global behavior and style of the compact menu and some additional settings related to the interface.') . '</p>', '#description_display' => 'before'); $form['details_compact_menu']['details_menu_style'] = array('#type' => 'details', '#title' => t('Style'), '#open' => FALSE); $form['details_compact_menu']['details_menu_style']['addthis_co_brand'] = array('#type' => 'textfield', '#title' => t('Branding text'), '#description' => t('Additional branding message to be rendered in the upper-right-hand corner of the compact menus.<br />Should be less than 15 characters in most cases to render properly.'), '#default_value' => $config->get('compact_menu.menu_style.addthis_co_brand'), '#required' => FALSE, '#maxlength' => 15); $form['details_compact_menu']['details_menu_style']['addthis_ui_header_color'] = array('#type' => 'textfield', '#title' => t('Header text color'), '#default_value' => $config->get('compact_menu.menu_style.addthis_ui_header_color'), '#description' => t('Something like \'#FFFFFF\'.'), '#size' => 8, '#maxlength' => 7, '#required' => FALSE); $form['details_compact_menu']['details_menu_style']['addthis_ui_header_background_color'] = array('#type' => 'textfield', '#title' => t('Header background color'), '#default_value' => $config->get('compact_menu.menu_style.addthis_ui_header_background_color'), '#description' => t('Something like \'#000000\'.'), '#size' => 8, '#maxlength' => 7, '#required' => FALSE); $form['details_compact_menu']['details_menu_style']['addthis_click_to_open_compact_menu_enabled'] = array('#type' => 'checkbox', '#title' => t('Open compact menu on click'), '#description' => t('Default behavior is to open compact menu on hover.'), '#default_value' => $config->get('compact_menu.menu_style.addthis_click_to_open_compact_menu_enabled'), '#required' => FALSE); $form['details_compact_menu']['details_menu_style']['addthis_open_windows_enabled'] = array('#type' => 'checkbox', '#title' => t('Use pop-up windows'), '#description' => t('If checked, all shares will open in a new pop-up window instead of a new tab or regular browser window.'), '#default_value' => $config->get('compact_menu.menu_style.addthis_open_windows_enabled'), '#required' => FALSE); $form['details_compact_menu']['details_menu_style']['addthis_ui_delay'] = array('#type' => 'textfield', '#title' => t('Menu open delay'), '#description' => t('Delay, in milliseconds, before compact menu appears when mousing over a regular button. Capped at 500 ms.'), '#default_value' => $config->get('compact_menu.menu_style.addthis_ui_delay'), '#required' => FALSE, '#size' => 3, '#maxlength' => 3); // Enabled services settings. $form['details_compact_menu']['enabled_services_details'] = array('#type' => 'details', '#title' => t('Compact menu enabled services'), '#description' => t('The sharing services you select here will be displayed in the compact menu. If you select no services, AddThis will provide a list of frequently used services. This list is updated regularly. <b>Notice that this setting does not define what services should be display in a toolbox.</b>'), '#description_display' => 'before', '#open' => FALSE); $form['details_compact_menu']['enabled_services_details']['addthis_enabled_services'] = array('#type' => 'checkboxes', '#title' => t('Enabled services'), '#options' => AddThis::getInstance()->getServices(), '#default_value' => $config->get('compact_menu.enabled_services.addthis_enabled_services'), '#required' => FALSE, '#columns' => 3); // Additional visual settings. $form['details_compact_menu']['details_additionals'] = array('#type' => 'details', '#title' => t('Additional configuration'), '#open' => FALSE); $form['details_compact_menu']['details_additionals']['addthis_standard_css_enabled'] = array('#type' => 'checkbox', '#title' => t('Use standard AddThis stylesheet'), '#description' => t('If not checked, AddThis will not load standard CSS file, allowing you to style everything yourself without incurring the cost of an additional load.'), '#default_value' => $config->get('compact_menu.additionals.addthis_standard_css_enabled'), '#required' => FALSE); $form['details_compact_menu']['details_additionals']['addthis_508_compliant'] = array('#type' => 'checkbox', '#title' => t('508 compliant'), '#description' => 'If checked, clicking the AddThis button will open a new window to a page that is keyboard navigable.', '#default_value' => $config->get('compact_menu.additionals.addthis_508_compliant'), '#required' => FALSE); $form['details_compact_menu']['details_additionals']['addthis_addressbook_enabled'] = array('#type' => 'checkbox', '#title' => t('Use addressbook'), '#description' => 'If checked, the user will be able import their contacts from popular webmail services when using AddThis\'s email sharing.', '#default_value' => $config->get('compact_menu.additionals.addthis_addressbook_enabled'), '#required' => FALSE); // Excluded Services. $form['details_excluded_services'] = array('#type' => 'details', '#title' => t('Excluded services'), '#description' => t('The sharing services you select here will be excluded from all AddThis menus. This applies globally.'), '#description_display' => 'before', '#open' => FALSE); $form['details_excluded_services']['addthis_excluded_services'] = array('#type' => 'checkboxes', '#title' => t('Excluded services'), '#options' => AddThis::getInstance()->getServices(), '#default_value' => $config->get('excluded_services.addthis_excluded_services'), '#required' => FALSE, '#columns' => 3); //Analytics settings. $profile_id = $config->get('analytics.addthis_profile_id'); $can_track_clicks = empty($profile_id) ? FALSE : TRUE; $form['details_analytics'] = array('#type' => 'details', '#title' => t('Analytics and Tracking'), '#open' => $can_track_clicks ? TRUE : FALSE); if (!$can_track_clicks) { $form['details_analytics']['can_track_notice'] = array('#theme' => 'html_tag', '#tag' => 'div', '#value' => t('For click analytics and statistics you have to provide a ProfileID from <a href="http://www.addthis.com">AddThis.com</a>. Register <a href="https://www.addthis.com/register" targt="_blank">here</a>.'), '#attributes' => array('class' => array('messages', 'warning'))); } $form['details_analytics']['addthis_profile_id'] = array('#type' => 'textfield', '#title' => t('AddThis ProfileID'), '#default_value' => $config->get('analytics.addthis_profile_id'), '#required' => FALSE, '#size' => 25, '#description' => t('ProfileID at <a href="http://addthis.com/" target="_blank">AddThis.com</a>. Required for statistics.')); $form['details_analytics']['addthis_clickback_tracking_enabled'] = array('#type' => 'checkbox', '#title' => t('Track clickback'), '#description' => 'Check to allow AddThis to append a variable to your URLs upon sharing. AddThis will use this to track how many people come back to your content via links shared with AddThis. Highly recommended. Always global.', '#default_value' => $config->get('analytics.addthis_clickback_tracking_enabled'), '#required' => FALSE); // Facebook Like tracking requires a namespace to be added. $rdf_enabled = \Drupal::moduleHandler()->moduleExists('rdf'); if (!$rdf_enabled) { $rdf_description = '<span class="admin-disabled">' . t('The RDF module needs to be enabled to support Facebook Like tracking support.<br />Enable the module on <a href="!modules">modules</a> page.', array('!modules' => base_path() . 'admin/modules')) . '</span>'; } else { $rdf_description = t('Check to enable Facebook Like tracking support. Always global.'); } $form['details_analytics']['title_facebook'] = array('#theme' => 'html_tag', '#tag' => 'div', '#value' => '<b>' . t('Facebook') . '</b>'); $form['details_analytics']['facebook_notice'] = array('#theme' => 'html_tag', '#tag' => 'p', '#value' => $rdf_description, '#access' => !$rdf_enabled); $form['details_analytics']['addthis_facebook_like_count_support_enabled'] = array('#type' => 'checkbox', '#title' => t('Enable Facebook Like tracking'), '#description' => Xss::filter($rdf_description, array('span')), '#default_value' => $config->get('analytics.addthis_facebook_like_count_support_enabled'), '#required' => FALSE, '#disabled' => !$rdf_enabled); // Google Analytics and Google Social Tracking support. $can_do_google_social_tracking = \Drupal::moduleHandler()->moduleExists('googleanalytics'); //@TODO Get back to this. $google_analytics_config = \Drupal::config(google_analytics . settings); $google_analytics_account = $google_analytics_config->get('google_analytics_account'); $is_google_analytics_setup = $can_do_google_social_tracking && isset($google_analytics_account); $form['details_analytics']['google_analytics'] = array('#theme' => 'html_tag', '#tag' => 'div', '#value' => '<b>' . t('Google Analytics') . '</b>'); if (!$can_do_google_social_tracking) { $form['details_analytics']['can_do_google_analytics'] = array('#theme' => 'html_tag', '#tag' => 'p', '#value' => '<span class="admin-disabled">' . t('Install/enable the <a href="http://drupal.org/project/google_analytics" target="_blank">Google Analytics</a> module for Social Tracking support.') . '</span>'); } elseif ($can_do_google_social_tracking && !$is_google_analytics_setup) { $form['details_analytics']['can_do_google_analytics'] = array('#theme' => 'html_tag', '#tag' => 'p', '#value' => '<span class="admin-disabled">' . t('Configure the Google Analytics module correctly with the account code to use this feature.') . '</span>'); } $form['details_analytics']['addthis_google_analytics_tracking_enabled'] = array('#type' => 'checkbox', '#title' => t('Track with Google Analytics'), '#description' => t('Check to track shares in your Google Analytics account reports (<a href="http://www.addthis.com/help/google-analytics-integration">more info</a>). Always global.'), '#default_value' => $config->get('analytics.addthis_google_analytics_tracking_enabled'), '#required' => FALSE, '#disabled' => !$is_google_analytics_setup); $form['details_analytics']['addthis_google_analytics_social_tracking_enabled'] = array('#type' => 'checkbox', '#title' => t('Track with Google Analytics social'), '#description' => t('Check to track shares in the new Google Analytics social interaction reports (<a href="http://www.addthis.com/help/google-analytics-integration#social">more info</a>). Always global.'), '#default_value' => $config->get('analytics.addthis_google_analytics_social_tracking_enabled'), '#required' => FALSE, '#disabled' => !$is_google_analytics_setup); // Third party settings. $form['third_party_details'] = array('#type' => 'details', '#title' => t('Third party settings'), '#open' => FALSE); $form['third_party_details']['twitter_service'] = array('#type' => 'fieldset', '#title' => t('Twitter'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['third_party_details']['twitter_service']['addthis_twitter_via'] = array('#type' => 'textfield', '#title' => t('Send via'), '#description' => t('When sending a tweet this is the screen name of the user to attribute the Tweet to. (Relates to Tweet Button)'), '#default_value' => $config->get('third_party.addthis_twitter_via'), '#size' => 15); $form['third_party_details']['twitter_service']['addthis_twitter_template'] = array('#type' => 'textfield', '#title' => t('Template text'), '#description' => t('The {{title}} and {{url}} are replaced from the Twitter Button.'), '#default_value' => $config->get('third_party.addthis_twitter_template')); return parent::buildForm($form, $form_state); }