Problem/Motivation

When sharing a site with query string (on which the query parameters control crucial page elements such as dynamic display of a video based on a query parameter for example), the query string gets cut off from the url that is actually shared.

This is bad if you really require the query parameters to get shared as well but can be prevented by enforcing rendering of addthis attributes. Unfortunately the current code won't allow adding OG tags and attributes at the same time.

Proposed resolution

Always enforce adding of addthis attributes.

Comments

s_leu’s picture

Issue summary: View changes
s_leu’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

Here's a first patch.

miro_dietiker’s picture

Status: Needs review » Needs work

As investigated today, I recommend to switch to always add this url.
With typical Drupal development patterns, query strings can be considered part of the URL, change the results (such as a view filter) and should not be automatically dropped, ever. This fix makes this explicit.

However, please add a comment about the original issue any why we enforce it.. and link to this issue.

Finally, sure, this kind of things should be easily alterable. But this should be covered in a followup. (please create)

miro_dietiker’s picture

Actually the special option to add the meta info into the inline attributes then has a different meaning:
It now is only to suppress the global OG tag overwriting.
I think, we should have here some better solution, at least detects clashes and warn. Possibly have some hierarchy / weights. Possibly also invert the checkbox to "promote to page OG tags". (followup)

berdir’s picture

As discussed:

- Drop the current flag
- Ad the view mode to $context before calling the alter hook
- support the following view modes:

full: Default, display og tags if first like now, always add atributes
only_og: like now, only og tags, no visible output
no_attributes: like full, but don't add attributes
no_og: like full, but don't add og tags.

Then document those somewhere, README.txt probably.

s_leu’s picture

Status: Needs work » Needs review
StatusFileSize
new9.49 KB
new9.35 KB

Ok here's a new patch considering the feedback and adding a test for the view modes.

Status: Needs review » Needs work

The last submitted patch, 6: always-enforce-addthis-attributes-2373217-6.patch, failed testing.

s_leu’s picture

Status: Needs work » Needs review
StatusFileSize
new8.42 KB
new6.26 KB

Changed test as discussed.

  • Berdir committed 873301d on 7.x-1.x authored by s_leu
    Issue #2373217 by s_leu: Fixed Addthis cuts off query from url, always...
berdir’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs review » Patch (to be ported)
StatusFileSize
new1.24 KB

Committed with the attached documentation changes. No need to be specific about entity reference there, view modes can always be used.

s_leu’s picture

Now that we have this patch committed i wonder if it's still necessary to have the option " Enforce the usage of this share message on the page it points to"?

berdir’s picture

Yes, definitely. That is what powers smid=1, this change only made it work out of the box, thanks to the attributes that are how there by default.

tduong’s picture

For now I have ported only the test. I'm not sure what to do about the view_mode array and where is/should be defined the sharemessage_entity_info() method. Any suggestion?

miro_dietiker’s picture

Status: Patch (to be ported) » Needs review

Let's see the tests running.

Status: Needs review » Needs work

The last submitted patch, 13: always-enforce-addthis-attributes-2373217-13-test_only.patch, failed testing.

miro_dietiker’s picture

+++ b/src/Tests/ShareMessageViewModesTest.php
@@ -0,0 +1,104 @@
+  protected function assertShareButtons($sharemessage, $addthis_attributes = FALSE, $invert = FALSE) {

This function contains too much logic. It reads "assertShareButtons()" and adding an $invert is really strange to read code without knowing the implementation.

Make it more self explaining. Some code duplication in tests does not hurt. Or create wrapper methods with nice names.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new3.76 KB
new5.06 KB

Split assertShareButtons(): getRawHtmlIconeStyle(), assertShareButton()

Status: Needs review » Needs work

The last submitted patch, 17: always-enforce-addthis-attributes-2373217-17.patch, failed testing.

miro_dietiker’s picture

Hm, i think i didn't explain well.

I mean we should do less arguments and make the method more self explanatory by name:
- assertShareButton()
- assertNoShareButton()
- assertOGTags()
- assertNoOGTags()
Internally you might want to have assertShareButtonHelper() or assertOGTagsHelper() with an extra argument to do the inverse check to avoid code duplication.
But the test code only calls the nicely named methods with only few arguments.

tduong’s picture

Assigned: Unassigned » tduong
tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new6.64 KB
new6.59 KB

Created the 6 assert methods mentioned in #19 and fixed the test method.

Status: Needs review » Needs work

The last submitted patch, 21: always-enforce-addthis-attributes-2373217-21.patch, failed testing.

miro_dietiker’s picture

Yeah now it reads much nicer!

Now just the functionality is missing..? ;-)

And about assertOGTags():

  1. +++ b/src/Tests/ShareMessageViewModesTest.php
    @@ -0,0 +1,170 @@
    +  protected function assertOGTagsHelper($title, $not_exists = TRUE) {
    

    Hm, we might want to verify more elements from OG than just the title. Or you think it is enough because covered elsewhere in more detail?

  2. +++ b/src/Tests/ShareMessageViewModesTest.php
    @@ -0,0 +1,170 @@
    +    $meta_title = '<meta property="og:title" content="' . $title . '" />';
    

    This loooks much risky if $title contains special characters such as "'" or '"'. The example should cover it to proof we have no XSS problems. And $title should be encoded here.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new3.65 KB
new11.14 KB

Tried to port the rest.

tduong’s picture

Oh, ok I'll do it next week :)

Status: Needs review » Needs work

The last submitted patch, 24: always-enforce-addthis-attributes-2373217-24.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new5.1 KB
new12.46 KB

Interdiff:

  • modified assertOGTags() / assertNoOGTags() / assertOGTagsHelper() parameter ($property, $value)

As discussed with @miro_dietiker we might want to move the OGTags assertion methods to a base class, since there is also other tests regarding these OG properties. Created issue here: #2638624: Move assertOGTags() from test to base class

Also we have added a @todo in Drupal\sharemessage\Tests\ShareMessageSettingsTest::testShareMessageOGTags() to add a coverage for a safer check for the special characters in OG Tags.
Created issue here: #2638628: Add test coverage for special characters in OG tags

The test is still failing and I'm still not sure if the last ported parts are ok. I thought that it should be added some lines in AddthisSettingsForm and sharemessage.addthis.yml to set which view_mode to use or something like that, am I right?

Status: Needs review » Needs work

The last submitted patch, 27: always-enforce-addthis-attributes-2373217-27.patch, failed testing.

miro_dietiker’s picture

Looks fine to me. Now let's make it pass... ;-)

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new12.75 KB

Fixed!

Status: Needs review » Needs work

The last submitted patch, 30: always-enforce-addthis-attributes-2373217-30.patch, failed testing.

tduong’s picture

Created an issue to move the ShareButtons assertion methods to the base class in #2639208: Move assertShareButtons() from test to base class, already uploaded the patch. Need to be approved and committed so I can reroll the patch of this issue and make this test to pass.

miro_dietiker’s picture

So referred things progressed... Now back to work in this issue and make it pass? ;-)

tduong’s picture

Yep, let's do it! :D

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new24.89 KB
new12.58 KB

Rerolled, fixed the additional AddThis attributes in the base class and the tests.

Status: Needs review » Needs work

The last submitted patch, 35: always-enforce-addthis-attributes-2373217-35.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new4.15 KB
new14.52 KB

Fixed! :D

Status: Needs review » Needs work

The last submitted patch, 37: always-enforce-addthis-attributes-2373217-37.patch, failed testing.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new2.59 KB
new15.07 KB

Fixed absolute url bug.

miro_dietiker’s picture

Status: Needs review » Fixed

I like! Committed! :-)

  • miro_dietiker committed affdacb on 8.x-1.x authored by tduong
    Issue #2373217 by tduong, s_leu, Berdir, miro_dietiker: Addthis cuts off...

Status: Fixed » Closed (fixed)

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