Skip to content

Commit

Permalink
Merge pull request #40 from ChuChuNaKu/cleanAddThisElementAddThisWrapper
Browse files Browse the repository at this point in the history
Clean add this element add this wrapper
  • Loading branch information
John Doyle committed Aug 21, 2015
2 parents edf4b63 + 2e3040e commit 526737c
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 210 deletions.
11 changes: 0 additions & 11 deletions addthis_block/addthis_block.info.yml

This file was deleted.

11 changes: 0 additions & 11 deletions addthis_fields/addthis_fields.info.yml

This file was deleted.

4 changes: 3 additions & 1 deletion src/Element/AddThisBasicButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class AddThisBasicButton extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
$config = $this->configuration;
return [
'#theme' => 'addthis_basic_button',
'#size' => 'small',
'#size' => $config['basic_button']['button_size'],
'#extra_classes' => $config['basic_button']['extra_css'],
'#pre_render' => [
[$class, 'preRender'],
],
Expand Down
89 changes: 5 additions & 84 deletions src/Element/AddThisBasicToolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,19 @@ class AddThisBasicToolbox extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
$config = $this->configuration;
return [
'#theme' => 'addthis_basic_toolbox',
'#size' => '',
'#services' => array(),
'#size' => $config['basic_toolbox']['buttons_size'],
'#services' => $config['basic_toolbox']['share_services'],
'#extra_classes' => $config['basic_toolbox']['extra_css'],
'#pre_render' => [
[$class, 'preRender'],
],
];
}

public function preRender($element) {
$element['addthis_basic_toolbox'] = 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 Script.
$element['#attached']['library'][] = 'addthis/addthis.widget';

Expand All @@ -62,75 +51,7 @@ public function preRender($element) {
$services = trim($element['#services']);
$services = str_replace(' ', '', $services);
$services = explode(',', $services);
// All service elements
$items = array();
foreach ($services as $service) {
$items[$service] = array(
'#type' => 'addthis_element',
'#tag' => 'a',
'value' => '',
'#attributes' => array(
//'href' => $script_manager->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' => $script_manager->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['addthis_basic_toolbox'] += $items;
$element['services'] = $services;

return $element;
}
Expand Down
30 changes: 0 additions & 30 deletions src/Element/AddThisElement.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Element/AddThisWrapper.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\addthis_block\Plugin\Block\AddThisBlock.
* Contains \Drupal\addthis\Plugin\Block\AddThisBlock.
*/

namespace Drupal\addthis_block\Plugin\Block;
namespace Drupal\addthis\Plugin\Block;

use Drupal\addthis\AddThisBasicButtonFormTrait;
use Drupal\addthis\AddThisBasicToolboxFormTrait;
Expand Down Expand Up @@ -69,8 +69,8 @@ function blockForm($form, FormStateInterface $form_state) {
'#title' => t('Formatter for @title', array('@title' => 'AddThis block')),
'#title_display' => 'invisible',
'#options' => [
'addthis_basic_button',
'addthis_basic_toolbox'
'addthis_basic_button' => 'AddThis Basic Button',
'addthis_basic_toolbox' => 'AddThis Basic Toolbox',
],
'#default_value' => $settings['type'],
'#attributes' => array('class' => array('addthis-display-type')),
Expand Down Expand Up @@ -160,13 +160,15 @@ public function build() {
return [
'#type' => 'addthis_basic_button',
'#size' => $config['basic_button']['button_size'],
'#extra_classes' => $config['basic_button']['extra_css'],
];
break;
case 'addthis_basic_toolbox':
return [
'#type' => 'addthis_basic_toolbox',
'#size' => $config['basic_toolbox']['buttons_size'],
'#services' => $config['basic_toolbox']['share_services'],
'#extra_classes' => $config['basic_toolbox']['extra_css'],
];
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\addthis_fields\Plugin\Field\FieldFormatter\AddThisBasicButtonFormatter.
* Contains \Drupal\addthis\Plugin\Field\FieldFormatter\AddThisBasicButtonFormatter.
*/

namespace Drupal\addthis_fields\Plugin\Field\FieldFormatter;
namespace Drupal\addthis\Plugin\Field\FieldFormatter;

use Drupal\addthis\AddThisBasicButtonFormTrait;
use Drupal\Core\Field\FormatterBase;
Expand Down Expand Up @@ -53,10 +53,10 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
*/
public function viewElements(FieldItemListInterface $items) {
$settings = $this->getSettings();
$add_this_service = \Drupal::service('addthis.addthis');
$markup = $add_this_service->getBasicButtonMarkup($settings);
return array(
'#markup' => $markup
'#type' => 'addthis_basic_button',
'#size' => $settings['basic_button']['button_size'],
'#extra_classes' => $settings['basic_button']['extra_css'],
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* @file
* Contains \Drupal\addthis_fields\Plugin\Field\FieldFormatter\AddThisBasicToolboxFormatter.
* Contains \Drupal\addthis\Plugin\Field\FieldFormatter\AddThisBasicToolboxFormatter.
*/

namespace Drupal\addthis_fields\Plugin\Field\FieldFormatter;
namespace Drupal\addthis\Plugin\Field\FieldFormatter;

use Drupal\addthis\AddThisBasicToolboxFormTrait;
use Drupal\Core\Field\FormatterBase;
Expand Down Expand Up @@ -54,12 +54,11 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
*/
public function viewElements(FieldItemListInterface $items) {
$settings = $this->getSettings();

$add_this_service = \Drupal::service('addthis.addthis');
$markup = $add_this_service->getBasicToolboxMarkup($settings);

return array(
'#markup' => $markup
'#type' => 'addthis_basic_toolbox',
'#size' => $settings['basic_toolbox']['buttons_size'],
'#services' => $settings['basic_toolbox']['share_services'],
'#extra_classes' => $settings['basic_toolbox']['extra_css'],
);
}

Expand Down
5 changes: 4 additions & 1 deletion templates/addthis-basic-button.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* @file
* Default theme implementation to display a node..
* Available variables:
* - element: AddThis Wrapper to be rendered
* - element: AddThis basic button to be rendered
*
*/
#}



<a class="addthis_button">
{{ element }}
</a>
7 changes: 6 additions & 1 deletion templates/addthis-basic-toolbox.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
*
*/
#}
{{ element }}

<div class="addthis_toolbox addthis_default_style {{ element['#extra_classes'] }} {{ element['#size'] }} ">
{% for service in element.services %}
<a class="addthis_button_{{ service }}" href="#" ></a>
{% endfor %}
</div>
12 changes: 0 additions & 12 deletions templates/addthis-element.html.twig

This file was deleted.

13 changes: 0 additions & 13 deletions templates/addthis-wrapper.html.twig

This file was deleted.

0 comments on commit 526737c

Please sign in to comment.