Currently the sharethis module only works with default view modes, and not those created by display suite or via hook_entity_info_alter. It also does not allow you the option of enabling it for search result or search index pages. I will be contributing a patch momentarily to make this work with both of these. An added benefit is that the logic for the hook_node_view implementation.

Comments

rlangille’s picture

Issue tags: +Promised patch
StatusFileSize
new10.4 KB

Here is the patch promised! Enjoy!

rlangille’s picture

Status: Active » Needs review
vchen’s picture

I'd love to try out this patch and review it. I'm sort of a newbie at applying patches. I know the basics of applying them manually, but this one is so long, I don't want to accidentally copy and paste the wrong thing in the wrong lines, or forget to delete everything that's needed.

Is there a way you can link it to a file with all the changes? Or is there a way that I don't know about to apply the changes faster without manually hunting down each chunk and making the changes?

Sorry if these are stupid questions.

hazah’s picture

Patch works as designed for me. Thanks!

kclarkson’s picture

I attempted to apply the patch using git but it didn't apply

hazah’s picture

I just copied the lines in and removed them manually right from my browser. I find that there's too much inconsistency so I just do this manually.

kclarkson’s picture

Can this patch be re-rolled so that it can be committed ?

Thanks !

jerenus’s picture

StatusFileSize
new8.53 KB

Re-rolled this patch for 7.x-2.x-dev. :)

robloach’s picture

The code looks pretty good, as long as we get some testers on it, I'd say it's RTBC.

tim.plunkett’s picture

StatusFileSize
new7.4 KB
new11.9 KB

Here's a different patch, one that utilizes hook_field_extra_fields(), allowing it to work with Display Suite, and have the positioning be customizable per view mode per entity type.
That makes the view mode and content type selector only relevant for the "links" placement, so I've used #states to toggle that, and the 'block' and 'content' help text.

This will make #1239418: Can't used sharthis with Display Suite obsolete.

tim.plunkett’s picture

Priority: Normal » Major
robloach’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! I hope to have time for this sometime soon :-) .

tim.plunkett’s picture

StatusFileSize
new11.69 KB
new1.37 KB

Oops, made one mistake.
We should write tests for this ;)

kclarkson’s picture

Would love to get this committed !

zambrey’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure if I'm doing something wrong but after applying #13 the widget is displayed on every node type, regardless of settings on Manage Display tab.

Also in code there is a duplicated weight key:

+        'sharethis' => array(
+          'label' => t('ShareThis'),
+          'description' => t('ShareThis links'),
+          'weight' => 0,
+          'weight' => intval(variable_get('sharethis_weight', 10)),
+        ),
Chaulky’s picture

Status: Needs work » Needs review
StatusFileSize
new11.66 KB

Removed the extra 'weight'. Will test shortly and report back.

Chaulky’s picture

StatusFileSize
new423 bytes

Meant to include an interdiff even though it's so tiny.

Chaulky’s picture

Status: Needs review » Needs work
+++ b/sharethis.moduleundefined
@@ -184,7 +154,44 @@ function sharethis_configuration_form($form, &$form_state) {
+  // Add checkboxes for each view mode of each bundle.
+  $entity_info = entity_get_info('node');
+  $modes = array();
+  foreach ($entity_info['view modes'] as $mode => $mode_info) {
+    $modes[$mode] = $mode_info['label'];
+  }
+  // Get a list of content types and view modes
+  $view_modes_selected = $current_options_array['view_modes'];
+  foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
+    $form['context']['links']['sharethis_' . $bundle . '_options'] = array(
+      '#title' => t('%label View Modes', array('%label' => $bundle_info['label'])),
+      '#description' => t('Select which view modes the ShareThis widget should appear on for %label nodes.', array('%label' => $bundle_info['label'])),
+      '#type' => 'checkboxes',
+      '#options' => $modes,
+      '#default_value' => $view_modes_selected[$bundle],
+    );

Why are you writing out all of the view modes? Is this to allow the user to choose which display modes will include the ShareThis buttons in the 'links'? If so, I get that, because we took away the "Show in Teaser" option and need to give it back somehow. But, for a site with a lot of content types, this quickly gets out of hand. We either need a better display for this (collapsible fieldsets or something) or we need to reduce the number of options.

+++ b/sharethis.moduleundefined
@@ -336,43 +350,57 @@ function sharethis_node_view($node, $view_mode, $langcode) {
+function sharethis_field_extra_fields() {
+  $extra = array();
+  // Only add extra fields if the location is the node content.
+  if (variable_get('sharethis_location', 'content') == 'content') {
+    $entity_info = entity_get_info('node');
+    foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
+      $extra['node'][$bundle]['display'] = array(
+        'sharethis' => array(
+          'label' => t('ShareThis'),
+          'description' => t('ShareThis links'),
+          'weight' => 0,
+          'weight' => intval(variable_get('sharethis_weight', 10)),
+        ),
+      );
     }
   }
+  return $extra;

This is going to add ShareThis buttons to every content type in every view mode. This is probably the wrong default behavior. Unfortunately it looks like you can't set it to hidden by default using hook_field_extra_fields().

Chaulky’s picture

#15 When using the 'Content' option, you have to make the ShareThis buttons hidden on each view mode for each content type that you don't want it to show up on. By default, it will show up on all of them.

Chaulky’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB
new0 bytes

Did some testing and updated the patch (interdiff included). I didn't have any problems with the view mode settings for the "Content" location that #15 mentioned. However, I noticed that the settings for the "Links area" view modes didn't actually do anything. I added the proper checks in sharethis_node_view(). I also added the option to choose which content types to enable ShareThis for when using the "Content" location. This was an effort to reduce the number of view modes you need to edit in "Manage Display" when you turn it on. This way if you have 6 node types, but you only enable it for one, you only need to go through the view mode settings for that one node type.

The UI still seems a little clunky, but I think it's good enough unless someone wants to spend more time polishing it.

Chaulky’s picture

StatusFileSize
new12.87 KB

Oops! Patch was empty, here it is for real this time.

altrugon’s picture

Patch in #21 can't be applied against the current 2.x-dev version.

molly_n’s picture

StatusFileSize
new13.35 KB

Here is a re-roll of the patch from #21 against the latest 7.x-2.x-dev

Status: Needs review » Needs work

The last submitted patch, sharethis-1555004-23.patch, failed testing.

molly_n’s picture

StatusFileSize
new13.22 KB

Oops, let's try this one

molly_n’s picture

Status: Needs work » Needs review
sardara’s picture

Patch seems good.

Gaofengzzz’s picture

Status: Needs review » Needs work

Pretty cool patch! I tested this patch from #25 and the new features works pretty fine.

But it seems this patch will break production server. I mean we need re-config Sharethis after apply this patch, otherwise these sharethis widgets will disappear. Maybe we need store $enabled_content_types in the same variable.

Gaofengzzz’s picture

Status: Needs work » Needs review

I think the status should be "need review".

Chaulky’s picture

The patch is already storing the new configuration in the {variables} table. I think we actually need to add an update hook to set the new configuration options based on the existing options. It's been a while since I worked on this patch, so I could be wrong.

kingswoodute’s picture

Hey guys, just wanted to say - may the force be with you.

I would love to be able to add sharethis links to my search results!

Gaofengzzz’s picture

Status: Needs review » Fixed

Thanks very much
After more than two weeks, with no particular objections or further issues on this ticket, I went ahead and got it committed against the 7.x-2.x branch at 519efd0.

I allowed myself to mark this issue as fixed for now, but feel free to re-open it, or post a new ticket, at any time if you have any further objections with this patch (we would surely be happy to hear your feedback).

Special thanks to @rlangille, @Jerenus, @Chaulky, @molly_n for re-implementing, Re-rolling, testing this patch.

Thanks again to everyone for your help, reviews, feedback and comments on this issue.

Cheers!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.