From 1835483286d77956fd8aabab11d3dae3fd505269 Mon Sep 17 00:00:00 2001 From: Brian Weaver <weaver.299@osu.edu> Date: Wed, 19 Feb 2020 13:49:47 -0500 Subject: [PATCH] Update social_media to 1.8 --- composer.lock | 22 +++-- vendor/composer/installed.json | 24 ++++-- web/modules/social_media/composer.json | 4 + .../config/install/social_media.settings.yml | 35 +++++--- web/modules/social_media/css/social_media.css | 18 ++-- .../social_media/icons/google_plus.svg | 1 - web/modules/social_media/icons/print.svg | 20 +++++ web/modules/social_media/icons/whatsapp.svg | 4 + web/modules/social_media/js/facebook.js | 5 +- web/modules/social_media/social_media.api.php | 19 ++-- .../social_media/social_media.info.yml | 12 ++- web/modules/social_media/social_media.install | 15 ++++ web/modules/social_media/social_media.module | 32 +++++-- .../social_media/social_media.routing.yml | 2 +- .../src/Controller/AccessController.php | 29 +++++++ .../src/Event/SocialMediaEvent.php | 21 +++-- .../src/Form/ForwardEmailForm.php | 26 +++--- .../src/Form/SocialMediaAdminForm.php | 86 +++++++++---------- .../src/Plugin/Block/SocialSharingBlock.php | 63 +++++++++----- .../FieldFormatter/SocialMediaFormatter.php | 9 +- .../Field/FieldType/SocialMediaItem.php | 3 +- .../Field/FieldWidget/SocialMediaWidget.php | 6 +- .../templates/social-media-links.html.twig | 2 +- 23 files changed, 296 insertions(+), 162 deletions(-) delete mode 100644 web/modules/social_media/icons/google_plus.svg create mode 100644 web/modules/social_media/icons/print.svg create mode 100644 web/modules/social_media/icons/whatsapp.svg create mode 100644 web/modules/social_media/social_media.install create mode 100644 web/modules/social_media/src/Controller/AccessController.php diff --git a/composer.lock b/composer.lock index bac7957e6d..5f0094a5c6 100644 --- a/composer.lock +++ b/composer.lock @@ -7291,20 +7291,21 @@ }, { "name": "drupal/social_media", - "version": "1.3.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/social_media.git", - "reference": "8.x-1.3" + "reference": "8.x-1.8" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/social_media-8.x-1.3.zip", - "reference": "8.x-1.3", - "shasum": "7b0ab2b3e368109343905c99beac4bd38a8b86a7" + "url": "https://ftp.drupal.org/files/projects/social_media-8.x-1.8.zip", + "reference": "8.x-1.8", + "shasum": "aaf92e087e5d3c4c6907b00b5dbb66b05eb5cda2" }, "require": { - "drupal/core": "*" + "drupal/core": "*", + "drupal/token": "*" }, "type": "drupal-module", "extra": { @@ -7312,8 +7313,8 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.3", - "datestamp": "1521748685", + "version": "8.x-1.8", + "datestamp": "1581591836", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -7329,6 +7330,11 @@ "name": "Takim Islam", "homepage": "http://drupalsharing.com/", "role": "Maintainer" + }, + { + "name": "Jack Over", + "homepage": "https://www.drupal.org/user/252386", + "role": "Maintainer" } ], "description": "Share current page to social media", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index c230e9d4a0..4de8c16e45 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -7520,21 +7520,22 @@ }, { "name": "drupal/social_media", - "version": "1.3.0", - "version_normalized": "1.3.0.0", + "version": "1.8.0", + "version_normalized": "1.8.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/social_media.git", - "reference": "8.x-1.3" + "reference": "8.x-1.8" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/social_media-8.x-1.3.zip", - "reference": "8.x-1.3", - "shasum": "7b0ab2b3e368109343905c99beac4bd38a8b86a7" + "url": "https://ftp.drupal.org/files/projects/social_media-8.x-1.8.zip", + "reference": "8.x-1.8", + "shasum": "aaf92e087e5d3c4c6907b00b5dbb66b05eb5cda2" }, "require": { - "drupal/core": "*" + "drupal/core": "*", + "drupal/token": "*" }, "type": "drupal-module", "extra": { @@ -7542,8 +7543,8 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.3", - "datestamp": "1521748685", + "version": "8.x-1.8", + "datestamp": "1581591836", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -7560,6 +7561,11 @@ "name": "Takim Islam", "homepage": "http://drupalsharing.com/", "role": "Maintainer" + }, + { + "name": "Jack Over", + "homepage": "https://www.drupal.org/user/252386", + "role": "Maintainer" } ], "description": "Share current page to social media", diff --git a/web/modules/social_media/composer.json b/web/modules/social_media/composer.json index 8761c1d9af..87f90ff60b 100644 --- a/web/modules/social_media/composer.json +++ b/web/modules/social_media/composer.json @@ -8,6 +8,10 @@ "name": "Takim Islam", "homepage": "http://drupalsharing.com/", "role": "Maintainer" + }, + { + "name": "Jack Over", + "role": "Maintainer" } ], "support": { diff --git a/web/modules/social_media/config/install/social_media.settings.yml b/web/modules/social_media/config/install/social_media.settings.yml index 1e0b3c997f..f8e985e879 100644 --- a/web/modules/social_media/config/install/social_media.settings.yml +++ b/web/modules/social_media/config/install/social_media.settings.yml @@ -6,7 +6,7 @@ social_media: api_event : "href" default_img: 1 weight: 1 - attributes : "target|_blank\nclass|facebook-share" + attributes : "target|_blank\nclass|facebook-share\nrel|nooopener noreffer" facebook_msg: enable: 1 api_url: "FB.ui({method: 'send',link: '[current-page:url]'})" @@ -16,7 +16,7 @@ social_media: text: "Facebook messenger" default_img: 1 weight: 2 - attributes : "target|_blank\nclass|facebook-msg" + attributes : "target|_blank\nclass|facebook-msg\nrel|nooopener noreffer" linkedin: enable: 1 api_url: "http://www.linkedin.com/shareArticle?mini=true&url=[current-page:url]&title=[current-page:title]&source=[current-page:url]" @@ -24,15 +24,15 @@ social_media: text: "Linkedin" default_img: 1 weight: 3 - attributes : "target|_blank\nclass|linkedin" + attributes : "target|_blank\nclass|linkedin\nrel|nooopener noreffer" twitter: enable: 1 - api_url: "https://twitter.com/intent/tweet?url=[current-page:url]&status=[current-page:title]+[current-page:url]" + api_url: "https://twitter.com/intent/tweet?url=[current-page:url]&url=[current-page:url]&hashtags=Hashtag" api_event : "href" text: "Twitter" default_img: 1 - weight: 4 - attributes : "target|_blank\nclass|twitter" + weight: 4 + attributes : "target|_blank\nclass|twitter\nrel|nooopener noreffer" pinterest: enable: 1 api_url: "https://www.pinterest.com/pin/create/button/?url=[current-page:url]&description=[current-page:title]" @@ -40,15 +40,14 @@ social_media: text: "Pinterest" default_img: 1 weight: 5 - attributes : "target|_blank\nclass|pinterest" - google_plus: - enable: 1 - text: "Google Plus" - api_url: "https://plus.google.com/share?url=[current-page:url]" - api_event : "href" + attributes : "target|_blank\nclass|pinterest\nrel|nooopener noreffer" + whatsapp: + enable: 0 + api_url: "https://wa.me/?text=[current-page:url]" + api_event: "href" default_img: 1 + attributes: "class|whatsapp show-for-small-only\ndata-action|share/whatsapp/share" weight: 6 - attributes : "target|_blank\nclass|google-plus" email: enable: 1 api_url: "mailto:?subject=[current-page:title]&body=Check out this site [current-page:url]" @@ -56,5 +55,13 @@ social_media: text: "Email" default_img: 1 weight: 7 - attributes : "class|email" + attributes : "class|email" + print: + enable: 0 + api_url: "window.print()" + api_event : "onclick" + text: "Print" + default_img: 1 + attributes : "class|print" + weight: 8 langcode: en diff --git a/web/modules/social_media/css/social_media.css b/web/modules/social_media/css/social_media.css index dda3cbc41e..64cce49aa9 100644 --- a/web/modules/social_media/css/social_media.css +++ b/web/modules/social_media/css/social_media.css @@ -1,20 +1,20 @@ -.social-media-sharing{ - display:block; +.social-media-sharing { + display: block; } .social-media-sharing ul { - padding-left:0px; + padding-left: 0px; display: inline-flex; text-align: center; } .social-media-sharing li { - display: inline-block; - margin-right: 15px; - list-style: none; - list-style-type: none; + display: inline-block; + margin-right: 15px; + list-style: none; + list-style-type: none; } .social-media-sharing .share { cursor: pointer; } .social-media-sharing .share img { - width:40px; -} \ No newline at end of file + width: 40px; +} diff --git a/web/modules/social_media/icons/google_plus.svg b/web/modules/social_media/icons/google_plus.svg deleted file mode 100644 index 4e27bc2e7c..0000000000 --- a/web/modules/social_media/icons/google_plus.svg +++ /dev/null @@ -1 +0,0 @@ -<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="social_x5F_0"><g><circle cx="255.672" cy="255.93" fill="#E7725D" r="256"/><path d="M255.672,511.93c141.386,0,256-114.611,256-256c0-68.156-26.688-130.043-70.116-175.917L77.414,439.582 C123.511,484.332,186.352,511.93,255.672,511.93z" fill="#D36955"/><path d="M343.103,121.873H225.67c-30.743,0-69.476,4.518-102.057,30.961 c-24.385,20.822-36.477,49.602-36.477,75.501c0,43.919,34.222,88.433,94.678,88.433c5.742,0,11.89-0.596,18.246-1.211 c-2.872,6.688-5.743,12.338-5.743,21.86c0,17.59,9.223,28.313,17.212,38.436c-25.816,1.62-73.564,4.469-109.023,25.916 c-15.194,8.883-25.584,19.624-32.441,30.602C82,444.921,95.179,456.263,109.43,466.193c-0.326-2.479-0.542-4.99-0.542-7.571 c0-40.074,36.475-53.629,48.972-58.078c23.976-7.879,54.717-8.91,59.838-8.91c5.731,0,8.604,0,13.114,0.418 c43.443,30.557,62.094,45.729,62.094,74.465c0,18.402-8.088,34.3-23.786,45.209c11.943-0.618,23.652-2.104,35.11-4.307 c17.857-18.404,26.994-40.718,26.994-62.959c0-38.861-22.742-58.086-47.962-78.729l-20.482-15.775 c-6.369-5.059-14.764-11.955-14.764-24.3c0-12.327,8.396-20.224,15.982-27.521c23.771-18.604,47.753-38.228,47.753-79.918 c0-42.854-27.266-65.381-40.371-76.082h35.246L343.103,121.873z M247.394,285.207c-9.213,8.902-24.586,15.782-38.724,15.782 c-49.188,0-71.321-62.521-71.321-100.368c0-14.565,2.872-29.744,12.504-41.564c9.215-11.271,25.196-18.6,39.955-18.6 c47.345,0,71.729,63,71.729,103.67C261.536,254.25,260.517,272.26,247.394,285.207z" fill="#FFFFFF"/><path d="M247.394,285.207c-7.006,6.768-17.571,12.348-28.45,14.641l-21.072,20.812 c-1.979,4.793-3.554,9.718-3.554,16.76c0,17.59,9.223,28.313,17.212,38.438c-20.092,1.261-53.453,3.308-83.979,14.242 l-50.238,49.606c9.942,9.652,20.707,18.451,32.104,26.404c-0.318-2.451-0.528-4.938-0.528-7.486 c0-40.074,36.475-53.629,48.972-58.078c23.976-7.879,54.718-8.91,59.839-8.91c5.73,0,8.604,0,13.113,0.418 c43.443,30.558,62.094,45.73,62.094,74.466c0,18.401-8.088,34.3-23.785,45.21c11.942-0.619,23.651-2.105,35.109-4.309 c17.857-18.404,26.994-40.717,26.994-62.959c0-38.86-22.742-58.086-47.962-78.729l-20.481-15.777 c-6.37-5.057-14.765-11.955-14.765-24.299c0-12.328,8.396-20.225,15.982-27.521c23.771-18.604,47.753-38.227,47.753-79.918 c0-3.297-0.21-6.436-0.518-9.497l-50.855,50.219C258.852,267.632,255.359,277.348,247.394,285.207z" fill="#F1F2F2"/><path d="M505.073,198.282c-0.375-1.631-0.72-3.271-1.128-4.888c-0.64-2.555-1.359-5.072-2.077-7.595 c-0.397-1.399-0.771-2.813-1.192-4.202c-0.308-1.008-0.653-1.996-0.979-2.996h-44.623v-56.729h-25.826v56.729h-55.078v24.461 h55.078v57.25h25.826v-57.25h51.064C505.787,201.469,505.439,199.872,505.073,198.282z" fill="#FFFFFF"/></g></g><g id="Layer_1_1_"/></svg> \ No newline at end of file diff --git a/web/modules/social_media/icons/print.svg b/web/modules/social_media/icons/print.svg new file mode 100644 index 0000000000..68a7f114c8 --- /dev/null +++ b/web/modules/social_media/icons/print.svg @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 40 40" style="enable-background:new 0 0 40 40;" xml:space="preserve"> +<style type="text/css"> + .st0{fill:#470A68;} + .st1{fill:#FFFFFF;} +</style> +<title>Shape</title> +<desc>Created with Sketch.</desc> +<circle class="st0" cx="20" cy="20" r="20"/> +<g> + <path class="st1" d="M26.4,17.3c0.6,0,1,0.2,1.4,0.6c0.4,0.4,0.6,0.9,0.6,1.4v3.5c0,0.1,0,0.3-0.1,0.4s-0.2,0.1-0.4,0.1h-1.5v3 + c0,0.3-0.1,0.5-0.3,0.7c-0.2,0.2-0.4,0.3-0.7,0.3h-10c-0.3,0-0.5-0.1-0.7-0.3c-0.2-0.2-0.3-0.4-0.3-0.7v-3h-1.5 + c-0.1,0-0.3,0-0.4-0.1s-0.1-0.2-0.1-0.4v-3.5c0-0.6,0.2-1,0.6-1.4s0.9-0.6,1.4-0.6v-5c0-0.3,0.1-0.5,0.3-0.7s0.4-0.3,0.7-0.3H24 + c0.3,0,0.5,0.1,0.7,0.3l1.4,1.4c0.2,0.2,0.3,0.4,0.3,0.7V17.3z M24.4,18.3v-3h-1.5c-0.1,0-0.3,0-0.4-0.1s-0.1-0.2-0.1-0.4v-1.5h-6 + v5H24.4z M24.4,25.3v-3h-8v3H24.4z M25.9,20.6c0.2,0,0.4-0.1,0.5-0.2c0.1-0.1,0.2-0.3,0.2-0.5s-0.1-0.4-0.2-0.5 + c-0.1-0.1-0.3-0.2-0.5-0.2c-0.2,0-0.4,0.1-0.5,0.2c-0.1,0.1-0.2,0.3-0.2,0.5s0.1,0.4,0.2,0.5C25.5,20.5,25.7,20.6,25.9,20.6z"/> +</g> +</svg> diff --git a/web/modules/social_media/icons/whatsapp.svg b/web/modules/social_media/icons/whatsapp.svg new file mode 100644 index 0000000000..8f4e24ddcd --- /dev/null +++ b/web/modules/social_media/icons/whatsapp.svg @@ -0,0 +1,4 @@ +<svg version="1.1" id="whatsapp-logo-notext" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 39 39" style="enable-background:new 0 0 39 39;" xml:space="preserve"><style type="text/css"> + .logo_white{fill:#FFFFFF;} + .logo_green{fill:#00E676;} + </style><path class="logo_green" d="M10.7,32.8l0.6,0.3c2.5,1.5,5.3,2.2,8.1,2.2l0,0c8.8,0,16-7.2,16-16c0-4.2-1.7-8.3-4.7-11.3 s-7-4.7-11.3-4.7c-8.8,0-16,7.2-15.9,16.1c0,3,0.9,5.9,2.4,8.4l0.4,0.6l-1.6,5.9L10.7,32.8z"/><path class="logo_white" d="M32.4,6.4C29,2.9,24.3,1,19.5,1C9.3,1,1.1,9.3,1.2,19.4c0,3.2,0.9,6.3,2.4,9.1L1,38l9.7-2.5 c2.7,1.5,5.7,2.2,8.7,2.2l0,0c10.1,0,18.3-8.3,18.3-18.4C37.7,14.4,35.8,9.8,32.4,6.4z M19.5,34.6L19.5,34.6c-2.7,0-5.4-0.7-7.7-2.1 l-0.6-0.3l-5.8,1.5L6.9,28l-0.4-0.6c-4.4-7.1-2.3-16.5,4.9-20.9s16.5-2.3,20.9,4.9s2.3,16.5-4.9,20.9C25.1,33.8,22.3,34.6,19.5,34.6 z M28.3,23.5L27.2,23c0,0-1.6-0.7-2.6-1.2c-0.1,0-0.2-0.1-0.3-0.1c-0.3,0-0.5,0.1-0.7,0.2l0,0c0,0-0.1,0.1-1.5,1.7 c-0.1,0.2-0.3,0.3-0.5,0.3h-0.1c-0.1,0-0.3-0.1-0.4-0.2l-0.5-0.2l0,0c-1.1-0.5-2.1-1.1-2.9-1.9c-0.2-0.2-0.5-0.4-0.7-0.6 c-0.7-0.7-1.4-1.5-1.9-2.4L15,18.4c-0.1-0.1-0.1-0.2-0.2-0.4c0-0.2,0-0.4,0.1-0.5c0,0,0.4-0.5,0.7-0.8c0.2-0.2,0.3-0.5,0.5-0.7 c0.2-0.3,0.3-0.7,0.2-1c-0.1-0.5-1.3-3.2-1.6-3.8c-0.2-0.3-0.4-0.4-0.7-0.5h-0.3c-0.2,0-0.5,0-0.8,0c-0.2,0-0.4,0.1-0.6,0.1 l-0.1,0.1c-0.2,0.1-0.4,0.3-0.6,0.4c-0.2,0.2-0.3,0.4-0.5,0.6c-0.7,0.9-1.1,2-1.1,3.1l0,0c0,0.8,0.2,1.6,0.5,2.3l0.1,0.3 c0.9,1.9,2.1,3.6,3.7,5.1l0.4,0.4c0.3,0.3,0.6,0.5,0.8,0.8c2.1,1.8,4.5,3.1,7.2,3.8c0.3,0.1,0.7,0.1,1,0.2l0,0c0.3,0,0.7,0,1,0 c0.5,0,1.1-0.2,1.5-0.4c0.3-0.2,0.5-0.2,0.7-0.4l0.2-0.2c0.2-0.2,0.4-0.3,0.6-0.5s0.4-0.4,0.5-0.6c0.2-0.4,0.3-0.9,0.4-1.4 c0-0.2,0-0.5,0-0.7C28.6,23.7,28.5,23.6,28.3,23.5z"/></svg> \ No newline at end of file diff --git a/web/modules/social_media/js/facebook.js b/web/modules/social_media/js/facebook.js index c271b894be..331dea1991 100644 --- a/web/modules/social_media/js/facebook.js +++ b/web/modules/social_media/js/facebook.js @@ -1,3 +1,7 @@ +/** + * @file + */ + (function ($) { 'use strict'; @@ -23,4 +27,3 @@ } }; })(jQuery); - diff --git a/web/modules/social_media/social_media.api.php b/web/modules/social_media/social_media.api.php index 84069513cb..4bf0a5e0b3 100644 --- a/web/modules/social_media/social_media.api.php +++ b/web/modules/social_media/social_media.api.php @@ -7,7 +7,7 @@ /** * Listens to the dynamic route events. */ -class socialMediaSubscriber implements EventSubscriberInterface { +class SocialMediaSubscriber implements EventSubscriberInterface { /** * Public static method used by Drupals event. @@ -16,18 +16,16 @@ class socialMediaSubscriber implements EventSubscriberInterface { * Array of events we subscribe to. */ public static function getSubscribedEvents() { - $events = array(); - $events['social_media.add_more_social_media'][] = array('addMoreSocialMedia', 39); - $events['social_media.pre_execute'][] = array('pre_executeSocialMedia', 39); - $events['social_media.pre_render'][] = array('pre_rednerSocialMedia', 39); + $events = []; + $events['social_media.add_more_social_media'][] = ['addMoreSocialMedia', 39]; + $events['social_media.pre_execute'][] = ['executeSocialMedia', 39]; + $events['social_media.pre_render'][] = ['renderSocialMedia', 39]; return $events; } - /** * Subscribes to social_media.add_more_social_media event. - * */ public function addMoreSocialMedia($event) { $element = $event->getElement(); @@ -37,20 +35,17 @@ public function addMoreSocialMedia($event) { /** * Subscribes to social_media.pre_execute event. - * */ - public function pre_executeSocialMedia($event) { + public function executeSocialMedia($event) { $element = $event->getElement(); $element['facebook_share']['weight'] = 8; $event->setElement($element); } - /** * Subscribes to social_media.pre_render event. - * */ - public function pre_rednerSocialMedia($event) { + public function renderSocialMedia($event) { $element = $event->getElement(); $element['facebook_msg']['text'] = 'New facebook msg text'; $event->setElement($element); diff --git a/web/modules/social_media/social_media.info.yml b/web/modules/social_media/social_media.info.yml index 509ed972a4..dec179f82d 100644 --- a/web/modules/social_media/social_media.info.yml +++ b/web/modules/social_media/social_media.info.yml @@ -1,16 +1,14 @@ name: Social media share type: module description: Share current page to social media -# core: 8.x +core: 8.x package: Others configure: social_media.admin_form dependencies: -- drupal:token +- token:token - drupal:field - -# Information added by Drupal.org packaging script on 2018-03-22 -version: '8.x-1.3' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-02-13 +version: '8.x-1.8' project: 'social_media' -datestamp: 1521748695 +datestamp: 1581591839 diff --git a/web/modules/social_media/social_media.install b/web/modules/social_media/social_media.install new file mode 100644 index 0000000000..ffe09b4363 --- /dev/null +++ b/web/modules/social_media/social_media.install @@ -0,0 +1,15 @@ +<?php + +/** + * Remove google plus configuration. + */ +function social_media_update_8001() { + \Drupal::configFactory()->getEditable('social_media.settings')->clear('google_plus')->save(); +} + +/** + * Implements hook_install(). + */ +function social_media_install() { + social_media_update_8001(); +} diff --git a/web/modules/social_media/social_media.module b/web/modules/social_media/social_media.module index 8f842b33b9..37f994ee37 100644 --- a/web/modules/social_media/social_media.module +++ b/web/modules/social_media/social_media.module @@ -5,19 +5,20 @@ * Contains social_media.module.. */ +use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_theme(). */ function social_media_theme($existing, $type, $theme, $path) { - return array( - 'social_media_links' => array( - 'variables' => array( + return [ + 'social_media_links' => [ + 'variables' => [ 'elements' => NULL, - ), + ], 'template' => 'social-media-links', - ) - ); + ], + ]; } /** @@ -33,4 +34,21 @@ function social_media_mail($key, &$message, $params) { $message['body'][] = $params['message']; break; } -} \ No newline at end of file +} + +/** + * Implements hook_help(). + */ +function social_media_help($route_name, RouteMatchInterface $route_match) { + + if ($route_name != 'help.page.social_media') { + return ''; + } + $output = ''; + $output .= '<h3>' . t('About') . '</h3>'; + $output .= '<p>' . t('The social media share module allows the user to share current page to different social media platforms. It is rendered as block, you can place it anywhere of your site.') . '</p>'; + $output .= '<p>' . t('Module provides social media field type so that you can add it as field in entity and take all benefits from field API.') . '</p>'; + $output .= '<p>' . t('It is flexible to share any page of the site whether it is node, term , panels, view pages so on.') . '</p>'; + $output .= '<p>' . t('Analyse the <a href="https://git.drupalcode.org/project/social_media/blob/8.x-1.x/README.txt">Read more</a> to get more information about this module.') . '</p>'; + return $output; +} diff --git a/web/modules/social_media/social_media.routing.yml b/web/modules/social_media/social_media.routing.yml index bb6961f80d..e8aced26b1 100644 --- a/web/modules/social_media/social_media.routing.yml +++ b/web/modules/social_media/social_media.routing.yml @@ -14,4 +14,4 @@ social_media.forward: _form: '\Drupal\social_media\Form\ForwardEmailForm' _title: 'Forward email' requirements: - _access: 'TRUE' \ No newline at end of file + _custom_access: '\Drupal\social_media\Controller\AccessController::access' diff --git a/web/modules/social_media/src/Controller/AccessController.php b/web/modules/social_media/src/Controller/AccessController.php new file mode 100644 index 0000000000..1d76f2601d --- /dev/null +++ b/web/modules/social_media/src/Controller/AccessController.php @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\social_media\Controller; + +use Drupal\Core\Access\AccessResult; +use Drupal\Core\Controller\ControllerBase; + +/** + * Class AccessController. + * + * @package Drupal\social_media\Controller + */ +class AccessController extends ControllerBase { + + /** + * Check if email option is enabled, if not do not allow this path. + * + * @return \Drupal\Core\Access\AccessResultInterface + * Return allowed if the social media email is enabled. + */ + public function access() { + $config = $this->config('social_media.settings'); + if ($config->get('social_media.email.enable') && $config->get('social_media.email.enable_forward')) { + return AccessResult::allowed()->addCacheableDependency($config); + } + return AccessResult::forbidden()->addCacheableDependency($config); + } + +} diff --git a/web/modules/social_media/src/Event/SocialMediaEvent.php b/web/modules/social_media/src/Event/SocialMediaEvent.php index 4230f9e13a..1e9504fc42 100644 --- a/web/modules/social_media/src/Event/SocialMediaEvent.php +++ b/web/modules/social_media/src/Event/SocialMediaEvent.php @@ -5,33 +5,44 @@ use Symfony\Component\EventDispatcher\Event; /** - * Class SocialMediaEvent + * Class SocialMediaEvent. */ class SocialMediaEvent extends Event { /** - * @var array. + * TODO describe element. + * + * @var array */ protected $element; /** * Constructor. + * + * @param array $element + * TODO describe what element is. */ - public function __construct($element) { + public function __construct(array $element) { $this->element = $element; } /** * Return the element. - * @return array() + * + * @return array + * The element. */ public function getElement() { return $this->element; } /** + * Element setter. + * + * @param array $element + * TODO describe what element is. */ - public function setElement($element) { + public function setElement(array $element) { $this->element = $element; } diff --git a/web/modules/social_media/src/Form/ForwardEmailForm.php b/web/modules/social_media/src/Form/ForwardEmailForm.php index 99bae9c732..a59288550a 100644 --- a/web/modules/social_media/src/Form/ForwardEmailForm.php +++ b/web/modules/social_media/src/Form/ForwardEmailForm.php @@ -13,10 +13,14 @@ /** * Class ForwardEmailForm. - * */ class ForwardEmailForm extends FormBase { + /** + * The config Factory. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ protected $configFactory; /** @@ -27,7 +31,7 @@ class ForwardEmailForm extends FormBase { protected $requestStack; /** - * The mail manager + * The mail manager. * * @var \Drupal\Core\Mail\MailManagerInterface */ @@ -107,31 +111,24 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => $this->t('Subject'), '#required' => TRUE, '#default_value' => $this->requestStack->getCurrentRequest() - ->get('subject') + ->get('subject'), ]; $form['body'] = [ '#type' => 'textarea', '#title' => $this->t('Body'), '#required' => TRUE, - '#default_value' => $this->requestStack->getCurrentRequest()->get('body') + '#default_value' => $this->requestStack->getCurrentRequest()->get('body'), ]; $form['submit'] = [ '#type' => 'submit', - '#value' => $this->t('Send') + '#value' => $this->t('Send'), ]; return $form; } - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - parent::validateForm($form, $form_state); - } - /** * {@inheritdoc} */ @@ -145,11 +142,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $result = $this->mailManager->mail('social_media', 'forward_email', $recipient, $langcode, $params, NULL, TRUE); if ($result['result'] !== TRUE) { $this->logger->notice('Sent email to %recipient', ['%recipient' => $recipient]); - drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error'); + $this->messenger()->addError($this->t('There was a problem sending your message and it was not sent.')); } else { $this->logger->notice('Sent email to %recipient', ['%recipient' => $recipient]); - drupal_set_message($this->t('Your message has been send to @email', ['@email' => $recipient])); + $this->messenger()->addMessage($this->t('Your message has been send to @email', ['@email' => $recipient])); } } + } diff --git a/web/modules/social_media/src/Form/SocialMediaAdminForm.php b/web/modules/social_media/src/Form/SocialMediaAdminForm.php index 5c10d6bd94..182a40e6f2 100644 --- a/web/modules/social_media/src/Form/SocialMediaAdminForm.php +++ b/web/modules/social_media/src/Form/SocialMediaAdminForm.php @@ -11,7 +11,6 @@ /** * Class SocialMediaAdminForm. - * */ class SocialMediaAdminForm extends ConfigFormBase { @@ -26,7 +25,8 @@ class SocialMediaAdminForm extends ConfigFormBase { * {@inheritdoc} */ public function __construct( - ConfigFactoryInterface $config_factory, EventDispatcherInterface $event_dispatcher) { + ConfigFactoryInterface $config_factory, + EventDispatcherInterface $event_dispatcher) { parent::__construct($config_factory); $this->eventDispatcher = $event_dispatcher; } @@ -65,16 +65,16 @@ public function buildForm(array $form, FormStateInterface $form_state) { $social_medias = $this->getSocialMedias(); $token_types = ['current_page']; foreach ($social_medias as $key => $label) { - $form[$key] = array( + $form[$key] = [ '#type' => 'details', - '#title' => t('@social_media settings', array('@social_media' => $label)), + '#title' => t('@social_media settings', ['@social_media' => $label]), '#open' => TRUE, - ); + ]; $form[$key][$key . '_enable'] = [ '#type' => 'checkbox', '#title' => $this->t('Enable'), '#default_value' => $config->get('social_media.' . $key . '.enable'), - '#description' => t('Globally disabled the settings') + '#description' => t('Globally disabled the settings'), ]; $form[$key][$key . '_api_url'] = [ @@ -83,6 +83,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('social_media.' . $key . '.api_url'), ]; + // Handle some extra help text for the Twitter service. + if ($key == 'twitter') { + $form[$key][$key . '_api_url']['#description'] = t('To include Hashtags format your URL like this: https://twitter.com/intent/tweet?url=[current-page:url]&text=[text to tweet]&hashtags=[comma separated list of hashtags, with no # on them]'); + } + $form[$key]['token_browser'] = [ '#theme' => 'token_tree_link', '#token_types' => $token_types, @@ -91,11 +96,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; // Handle some extra configuration for email service. - if($key == 'email'){ + if ($key == 'email') { $form[$key][$key . '_api_url']['#states'] = [ 'invisible' => [ - ':input[name="'.$key . '_enable_forward'.'"]' => array('checked' => TRUE), + ':input[name="' . $key . '_enable_forward' . '"]' => ['checked' => TRUE], ], ]; @@ -103,26 +108,26 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('Enable forward instead for client email service'), '#default_value' => $config->get('social_media.' . $key . '.enable_forward'), - '#description' => t('If it is checked then forward email form will open as model dialog.') + '#description' => t('If it is checked then forward email form will open as model dialog.'), ]; $form[$key][$key . '_show_forward'] = [ '#type' => 'radios', - '#options' => [1 => $this->t('Model dialog'),2 => $this->t('Separate page')], + '#options' => [1 => $this->t('Model dialog'), 2 => $this->t('Separate page')], '#title' => $this->t('Choose how you want to show forward email form'), - '#default_value' => $config->get('social_media.' . $key . '.show_forward')?$config->get('social_media.' . $key . '.show_forward'):1, + '#default_value' => $config->get('social_media.' . $key . '.show_forward') ? $config->get('social_media.' . $key . '.show_forward') : 1, '#states' => [ 'visible' => [ - ':input[name="'.$key . '_enable_forward'.'"]' => array('checked' => TRUE), - ], + ':input[name="' . $key . '_enable_forward' . '"]' => ['checked' => TRUE], ], - '#description' => t('default set as dialog popup, you can change it to show in separate page') + ], + '#description' => t('default set as dialog popup, you can change it to show in separate page'), ]; } $form[$key][$key . '_api_event'] = [ '#type' => 'select', '#title' => $this->t('Event'), - '#options' => array('href' => 'href', 'onclick' => 'onclick'), + '#options' => ['href' => 'href', 'onclick' => 'onclick'], '#default_value' => $config->get('social_media.' . $key . '.api_event'), ]; @@ -130,39 +135,39 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textarea', '#title' => $this->t('drupalSettings variables'), '#default_value' => $config->get('social_media.' . $key . '.drupalSettings'), - '#description' => t('Defines different drupalSettings variable.Each settings in new line.eg:<br/>application_id|343434434<br/>' . - 'you can get those variables in js.eg drupalSettings.social_media.application_id') + '#description' => t('Defines different drupalSettings variable.Each settings in new line.eg:<br/>application_id|343434434<br/> you can get those variables in js.eg drupalSettings.social_media.application_id'), ]; $form[$key][$key . '_library'] = [ '#type' => 'textfield', '#title' => $this->t('Drupal library'), '#default_value' => $config->get('social_media.' . $key . '.library'), - '#description' => t('Add drupal custom library.eg: social_media/facebook') + '#description' => t('Add drupal custom library.eg: social_media/facebook'), ]; - $form[$key][$key . '_text'] = [ '#type' => 'textfield', '#title' => $this->t('Link text'), '#default_value' => $config->get('social_media.' . $key . '.text'), - '#description' => t('Text of the link') + '#description' => t('Text of the link'), ]; $form[$key][$key . '_default_img'] = [ '#type' => 'checkbox', '#title' => $this->t('Default image'), '#default_value' => $config->get('social_media.' . $key . '.default_img'), - '#description' => t('If it is checked default image will be loaded. Make service name with icon name. eg:facebook_share.svg') + '#description' => t('If it is checked default image will be loaded. Make service name with icon name. eg:facebook_share.svg'), ]; $form[$key][$key . '_img'] = [ '#type' => 'textfield', '#title' => $this->t('Alternative image link'), - '#states' => array('visible' => array( - ':input[name="' . $key . '_default_img' . '"]' => array('checked' => FALSE), - )), + '#states' => [ + 'visible' => [ + ':input[name="' . $key . '_default_img' . '"]' => ['checked' => FALSE], + ], + ], '#default_value' => $config->get('social_media.' . $key . '.img'), - '#description' => t('If you want to have your custom image, give image path.') + '#description' => t('If you want to have your custom image, give image path.'), ]; $form[$key][$key . '_weight'] = [ '#type' => 'number', @@ -170,27 +175,19 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#max' => 10, '#min' => 0, '#default_value' => $config->get('social_media.' . $key . '.weight'), - '#description' => t('Order of the share link to render') + '#description' => t('Order of the share link to render'), ]; $form[$key][$key . '_attributes'] = [ '#type' => 'textarea', '#title' => $this->t('Attributes'), '#default_value' => $config->get('social_media.' . $key . '.attributes'), - '#description' => t('Defines different attributes of link. Each attribute in new line.eg:<br/>target|blank<br/>' - . 'class|facebook-share js-share') + '#description' => t('Defines different attributes of link. Each attribute in new line.eg:<br/>target|blank<br/> class|facebook-share js-share'), ]; } return parent::buildForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - parent::validateForm($form, $form_state); - } - /** * {@inheritdoc} */ @@ -238,29 +235,32 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } $config->save(); - drupal_set_message($this->t('Your configuration has been saved')); + $this->messenger()->addMessage($this->t('Your configuration has been saved')); } /** + * Get social media elements. * - * @return type + * @return array + * Social media elements. */ protected function getSocialMedias() { - $element = array( + $elements = [ 'facebook_share' => 'Facebook share', 'facebook_msg' => 'Facebook messenger', 'linkedin' => 'Linkedin', 'twitter' => 'Twitter', 'pinterest' => 'Pinterest', - 'google_plus' => 'Google Plus', 'email' => 'Email', - ); + 'whatsapp' => 'whatsapp', + 'print' => 'Print', + ]; - $event = new SocialMediaEvent($element); + $event = new SocialMediaEvent($elements); $this->eventDispatcher->dispatch('social_media.add_more_link', $event); - $element = $event->getElement(); + $elements = $event->getElement(); - return $element; + return $elements; } } diff --git a/web/modules/social_media/src/Plugin/Block/SocialSharingBlock.php b/web/modules/social_media/src/Plugin/Block/SocialSharingBlock.php index fd0a193a48..02470aaa07 100644 --- a/web/modules/social_media/src/Plugin/Block/SocialSharingBlock.php +++ b/web/modules/social_media/src/Plugin/Block/SocialSharingBlock.php @@ -11,6 +11,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Drupal\Core\Template\Attribute; use Drupal\Core\Path\CurrentPathStack; +use Drupal\Core\Cache\Cache; /** * Provides a 'SocialSharingBlock' block. @@ -79,11 +80,11 @@ public function build() { $library = ['social_media/basic']; $settings = []; $icon_path = $base_url . '/' . drupal_get_path('module', 'social_media') . '/icons/'; - $elements = array(); + $elements = []; $social_medias = $this->configFactory->get('social_media.settings') ->get('social_media'); - // call pre_execute event before doing anything. + // Call pre_execute event before doing anything. $event = new SocialMediaEvent($social_medias); $this->eventDispatcher->dispatch('social_media.pre_execute', $event); $social_medias = $event->getElement(); @@ -91,7 +92,7 @@ public function build() { $social_medias = $this->sortSocialMedias($social_medias); foreach ($social_medias as $name => $social_media) { - // replace api url with different link. + // Replace api url with different link. if ($name == "email" && isset($social_media['enable_forward']) && $social_media['enable_forward']) { $social_media['api_url'] = str_replace('mailto:', '/social-media-forward', $social_media['api_url']); $social_media['api_url'] .= '&destination=' . $this->currentPath->getPath(); @@ -102,16 +103,16 @@ public function build() { if ($social_media['enable'] == 1 && !empty($social_media['api_url'])) { $elements[$name]['text'] = $social_media['text']; - $elements[$name]['api'] = new Attribute(array($social_media['api_event'] => $this->token->replace($social_media['api_url']))); + $elements[$name]['api'] = new Attribute([$social_media['api_event'] => $this->token->replace($social_media['api_url'])]); if (isset($social_media['library']) && !empty($social_media['library'])) { $library[] = $social_media['library']; } if (isset($social_media['attributes']) && !empty($social_media['attributes'])) { - $elements[$name]['attr'] = $this->social_media_convert_attributes($social_media['attributes']); + $elements[$name]['attr'] = $this->socialMediaConvertAttributes($social_media['attributes']); } if (isset($social_media['drupalSettings']) && !empty($social_media['drupalSettings'])) { - $settings['social_media'] = $this->social_media_convert_drupalSettings($social_media['drupalSettings']); + $settings['social_media'] = $this->socialMediaConvertDrupalSettings($social_media['drupalSettings']); } if (isset($social_media['default_img']) && $social_media['default_img']) { @@ -133,31 +134,25 @@ public function build() { $build = []; - // call prerender event before render. + // Call prerender event before render. $event = new SocialMediaEvent($elements); $this->eventDispatcher->dispatch('social_media.pre_render', $event); $elements = $event->getElement(); - $build['social_sharing_block'] = array( + $build['social_sharing_block'] = [ '#theme' => 'social_media_links', '#elements' => $elements, '#attached' => [ 'library' => $library, - 'drupalSettings' => $settings + 'drupalSettings' => $settings, ], - '#cache' => [ - 'tags' => [ - 'social_media:' . $this->currentPath->getPath(), - ], - 'contexts' => [ - 'url', - ], - ], - ); - //dsm($build); + ]; return $build; } + /** + * TODO describe what this does and what $element is. + */ protected function sortSocialMedias(&$element) { $weight = []; foreach ($element as $key => $row) { @@ -167,11 +162,17 @@ protected function sortSocialMedias(&$element) { return $element; } - protected function social_media_convert_attributes($variables) { + /** + * TODO describe what this does and what $variables is. + */ + protected function socialMediaConvertAttributes($variables) { $variable = explode("\n", $variables); $attributes = []; if (count($variable)) { foreach ($variable as $each) { + if ($each === '') { + continue; + } $var = explode("|", $each); $value = str_replace(["\r\n", "\n", "\r"], "", $var[1]); $attributes[$var[0]] = new Attribute([$var[0] => $value]); @@ -180,7 +181,10 @@ protected function social_media_convert_attributes($variables) { return $attributes; } - protected function social_media_convert_drupalSettings($variables) { + /** + * TODO describe what this does and what $variables is. + */ + protected function socialMediaConvertDrupalSettings($variables) { $variable = explode("\n", $variables); $settings = []; if (count($variable)) { @@ -193,4 +197,21 @@ protected function social_media_convert_drupalSettings($variables) { return $settings; } + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return Cache::mergeTags(parent::getCacheTags(), [ + 'social_media:' . $this->currentPath->getPath(), + 'config:social_media.settings', + ]); + } + + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return Cache::mergeContexts(parent::getCacheContexts(), ['url.path']); + } + } diff --git a/web/modules/social_media/src/Plugin/Field/FieldFormatter/SocialMediaFormatter.php b/web/modules/social_media/src/Plugin/Field/FieldFormatter/SocialMediaFormatter.php index 1eb28da398..560c3cba40 100644 --- a/web/modules/social_media/src/Plugin/Field/FieldFormatter/SocialMediaFormatter.php +++ b/web/modules/social_media/src/Plugin/Field/FieldFormatter/SocialMediaFormatter.php @@ -21,7 +21,7 @@ * } * ) */ -class SocialMediaFormatter extends FormatterBase implements ContainerFactoryPluginInterface { +class SocialMediaFormatter extends FormatterBase implements ContainerFactoryPluginInterface { /** * The block manager. @@ -46,6 +46,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container->get('plugin.manager.block') ); } + /** * {@inheritdoc} */ @@ -56,10 +57,10 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $config = []; $block_instance = $this->blockManager->createInstance('social_sharing_block', $config); - // Some blocks might implement access check. + // Some blocks might implement access check. $access_result = $block_instance->access(\Drupal::currentUser()); - // Return empty render array if user doesn't have access. - // $access_result can be boolean or an AccessResult class + // Return empty render array if user doesn't have access. + // $access_result can be boolean or an AccessResult class. if (is_object($access_result) && $access_result->isForbidden() || is_bool($access_result) && !$access_result) { return []; } diff --git a/web/modules/social_media/src/Plugin/Field/FieldType/SocialMediaItem.php b/web/modules/social_media/src/Plugin/Field/FieldType/SocialMediaItem.php index a4e0cfe2dc..beeb7234a3 100644 --- a/web/modules/social_media/src/Plugin/Field/FieldType/SocialMediaItem.php +++ b/web/modules/social_media/src/Plugin/Field/FieldType/SocialMediaItem.php @@ -23,7 +23,7 @@ * default_formatter = "social_media_default" * ) */ -class SocialMediaItem extends FieldItemBase implements OptionsProviderInterface { +class SocialMediaItem extends FieldItemBase implements OptionsProviderInterface { /** * {@inheritdoc} @@ -60,7 +60,6 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel return $properties; } - /** * {@inheritdoc} */ diff --git a/web/modules/social_media/src/Plugin/Field/FieldWidget/SocialMediaWidget.php b/web/modules/social_media/src/Plugin/Field/FieldWidget/SocialMediaWidget.php index 58f1e0b391..ffbbaaa1ee 100644 --- a/web/modules/social_media/src/Plugin/Field/FieldWidget/SocialMediaWidget.php +++ b/web/modules/social_media/src/Plugin/Field/FieldWidget/SocialMediaWidget.php @@ -59,9 +59,9 @@ public function settingsSummary() { */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $element['value'] = $element + [ - '#type' => 'checkbox', - '#default_value' => !empty($items[0]->value), - ]; + '#type' => 'checkbox', + '#default_value' => !empty($items[0]->value), + ]; // Override the title from the incoming $element. if ($this->getSetting('display_label')) { diff --git a/web/modules/social_media/templates/social-media-links.html.twig b/web/modules/social_media/templates/social-media-links.html.twig index 85c1e4a5e7..fa03431c32 100644 --- a/web/modules/social_media/templates/social-media-links.html.twig +++ b/web/modules/social_media/templates/social-media-links.html.twig @@ -20,7 +20,7 @@ {% set dialogOptions = "data-dialog-options=" ~ {'width': '600'}|json_encode %} {% endif %} <li> - <a {{ dialogType }} {{ dialogOptions }} {{ element.attr.target }} {{ element.attr.class.addClass(classes) }} {{ element.api }} + <a {{ dialogType }} {{ dialogOptions }} {{ element.attr.target }} {{ element.attr.rel }} {{ element.attr.class.addClass(classes) }} {{ element.api }} title="{{ element.text }}"> {% if element.img %} <img alt="{{ element.text }}" src="{{ element.img }}"> -- GitLab