Support for

  • WhatsApp via URL
  • Print via URL and URL parameters
  • PDF documents via URL and URL parameters
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Knud Frank created an issue. See original summary.

Knud Frank’s picture

Here is a patch to solve the issue.

fago’s picture

Status: Active » Needs work

Thanks for the patch. Here a few remarks:

>The URL for PDF document.
for *the* PDF document

>+ * id = "link_PDF",
IDs should be all lowercase. Same for print.

>The text of the Print link."),
a print link is not a special thing, so let's keep spelling it all lowercase "print link" in sentences. Thus "Print" should be lowercased "print" in sentences everywhere.

>+ * description = @Translation("The URL for Print. When set to '<current>', the current page's URL is used."),
Can be default imo.

>the current page's URL is used.
I think that's wrong. It uses only the current page's path, not the full URL, or does it? Are present query paramters kept, shoudl they be kept? Let's be precise here.

>+{{ attach_library('social_share/popup') }}

I don't see why PDFs would open in a popup dialog. Let's use target blank, but no popup. Probably same for others.

+{% if print_url == '<current>' %}
+  {% set print_url = url('<current>')|render|striptags %}
+{% endif %}
+
+{% if '?' in print_url %}
+  {% set print_url_array = print_url|split('?') %}
+  {% set print_url = print_url_array[0] ~ '?' ~ print_url_array[1]|url_encode %}
+{% endif %}

I dislike that complexity in the template + it seems to be unnecessary complex:

Query parameter should be passed to the $options parameter of the url function, see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for docs of the options. I think you can just split the string by & and it should be fine.

+ *     "pdf_parameter" = @ContextDefinition("string",
+ *       label = @Translation("PDF document parameter"),
+ *       description = @Translation("Some ampersand(&)-separated parameters and values to pass with the PDF document URL."),
+ *       required = false,
+ *       default_value = "pdf=1"
+ *     ),

Should be called "pdf_url_query" - or url query parameter but that would be come a bit long.
Label: "PDF document URL query parameter"
Description: Some query parameters to append to the PDF document URL. Multiple values can be separated by ampersands (&).

Same for print parameters.

Knud Frank’s picture

Adjusted all files with regard to the comments from fago.

fago’s picture

Status: Needs work » Needs review
fago’s picture

Status: Needs review » Needs work
+  {% for parameter in parameters %}
+    {% set parameter_array = parameter|split('=') %}
+    {% set routeparameters = routeparameters|merge({ (parameter_array[0]|url_encode): (parameter_array[1]|url_encode) }) %}
+  {% endfor %}
+{% endif %}

Let's move this logic in the preprocessors, it does not make much sense to do this in the template.

Also what's app has a popup left, what we do not need.

Knud Frank’s picture

Status: Needs work » Needs review
StatusFileSize
new12.08 KB

Logic moved to preprocessor.
Removed popup from WhatsApp template.

Knud Frank’s picture

StatusFileSize
new12.08 KB
Knud Frank’s picture

StatusFileSize
new12.08 KB

Corrected file. Please disregard patch 7.

fago’s picture

Status: Needs review » Needs work

+ global $base_root;
+ $current_uri = \Drupal::request()->getRequestUri();
+ $current_path = $base_root . $current_uri;
+

ouch, no globals please - there must be some API to achieve what you need. Like \Drupal::request()->getRequestUri() or \Drupal::request()->getUri()

+    // Step through all social share settings and resolve <current> URLs.
+    foreach ($variables['content'] as $elements_key => $elements_array) {
+      foreach ($elements_array as $key => $value) {
+        if ($value == '<current>') {
+          $variables['content'][$elements_key][$key] = $current_path;
+        }
+      }
+    }

No guessing, please - this can create troubles. Please only processes a fixed list of url properties.

+{% set url = url|default(url('<current>')|render|striptags) %}
Should be removed and rely on the URL variable being preprocessed now. Same for "+ 'url': url|default(url('')|render|striptags)," of course.

Knud Frank’s picture

Status: Needs work » Needs review
StatusFileSize
new15.01 KB

Absolute URL can be achieved with \Drupal::request()->getUri().
Processed only the fields url and twitter_url to avoid troubles with other fields.
URLs are no longer set in Twig templates as code has benn moved to preprocess function.

fago’s picture

Status: Needs review » Needs work
+
+/**
+ * Implements hook_preprocess_block().
+ */
+function social_share_preprocess_block(&$variables) {

This will miss things when the field formatter is used :(

Let's just add a custom preprocess function like "social_share_preprocess_template_urls"

>$info['preprocess functions'][] = 'social_share_preprocess_template_urls';

Knud Frank’s picture

Status: Needs work » Needs review
StatusFileSize
new17.01 KB

Added a custom preprocess function.

siva01’s picture

Last patch social_share-whatsapp_print_pdf-2954288-13.patch hasn't defined WhatsApp message and url_params in twig message. There is update.

vandna b’s picture

#14 working fine for me.

a.milkovsky’s picture

Status: Needs review » Needs work

#14 works good, but it removes the PrintShareLink.

a.milkovsky’s picture

Status: Needs work » Needs review
StatusFileSize
new27.51 KB

Fixed #14, added missing files like PrintShareLink.php.

a.milkovsky’s picture

StatusFileSize
new26.86 KB

Fixed the function duplication.

a.milkovsky’s picture

StatusFileSize
new17.18 KB

Last patch contained file duplicates. Fixed it.

a.milkovsky’s picture

Hey, @Knud Frank let's RTBC and commit this feature/

ckohl’s picture

This patch fixes the "context_definitions" annotation

michaellenahan’s picture

This patch provides drupal 10 compatability, following on from https://www.drupal.org/project/social_share/issues/3378493

michaellenahan’s picture

#22 patch was incomplete, here is the correct patch.

michaellenahan’s picture

michaellenahan’s picture

Sorry for the noise. Here is the patch for drupal 10, including the changes from here: https://www.drupal.org/project/social_share/issues/3378493

tienwang’s picture

D10 patch (including the tweak for PrintShareLink.php)

volkerk made their first commit to this issue’s fork.

volkerk’s picture

StatusFileSize
new18.92 KB

Add patch for project installs.
Its same as social_share-whatsapp_print_pdf-2954288-26.patch but catering to typed_data update, see also #3461912: Fatal error on upgrade of typed_data dependencies

daniel.bosen’s picture

Status: Needs review » Reviewed & tested by the community

The concerns in #2954288-12: Support for WhatsApp, Print and PDF documents are addressed, the code looks good and this is actually running for 6 years in our projects. This looks good to me :-)

  • fago committed 0a29a1a1 on 8.x-2.x authored by volkerk
    Issue #2954288 by Knud Frank, a.milkovsky, michaellenahan, volkerk,...
fago’s picture

This seems fine indeed. Let's finally move on here ;-)

fago’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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