From 9ee561cf11a22bb50c6b74ab89cde971384eae69 Mon Sep 17 00:00:00 2001 From: Brian Canini <canini.16@osu.edu> Date: Thu, 11 Jun 2020 15:28:47 -0400 Subject: [PATCH] Updating drupal/addtocalendar (3.1.0 => 3.2.0) --- composer.json | 2 +- composer.lock | 23 ++--- vendor/composer/installed.json | 23 ++--- .../addtocalendar/addtocalendar.info.yml | 12 +-- .../addtocalendar/addtocalendar.libraries.yml | 1 + .../addtocalendar/addtocalendar.services.yml | 2 +- .../includes/addtocalendar.build.inc | 3 +- .../includes/addtocalendar.form.inc | 2 +- web/modules/addtocalendar/js/addtocalendar.js | 11 +++ .../src/AddToCalendarApiWidget.php | 95 +++++++++++++++++-- .../Field/FieldFormatter/AddToCalendar.php | 77 +++++++++++++-- 11 files changed, 202 insertions(+), 49 deletions(-) create mode 100644 web/modules/addtocalendar/js/addtocalendar.js diff --git a/composer.json b/composer.json index a5f42a493c..ffa003bc80 100644 --- a/composer.json +++ b/composer.json @@ -87,7 +87,7 @@ "dimsemenov/magnific-popup": "1.1", "drupal-composer/drupal-scaffold": "2.5.4", "drupal/address": "1.1", - "drupal/addtocalendar": "3.1", + "drupal/addtocalendar": "3.2", "drupal/admin_toolbar": "2.2", "drupal/administerusersbyrole": "3.0", "drupal/allowed_formats": "1.2", diff --git a/composer.lock b/composer.lock index b2df2fd7c7..6630852125 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "807a55f9c8496dc8ac9059ce43ee7a4f", + "content-hash": "235e3180c4a1e80e44ce51ebbaf068ec", "packages": [ { "name": "alchemy/zippy", @@ -2047,29 +2047,26 @@ }, { "name": "drupal/addtocalendar", - "version": "3.1.0", + "version": "3.2.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/addtocalendar.git", - "reference": "8.x-3.1" + "reference": "8.x-3.2" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.1.zip", - "reference": "8.x-3.1", - "shasum": "c384df6017790173908ee7566e2af22ab5234b9d" + "url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.2.zip", + "reference": "8.x-3.2", + "shasum": "b739326d98008f4091f71e0d5d21b5baa93a5dec" }, "require": { - "drupal/core": "*" + "drupal/core": "^8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { - "version": "8.x-3.1", - "datestamp": "1511952790", + "version": "8.x-3.2", + "datestamp": "1591246880", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -2112,7 +2109,7 @@ "description": "Add to calendar button to be used for event page.", "homepage": "https://www.drupal.org/project/addtocalendar", "support": { - "source": "http://cgit.drupalcode.org/addtocalendar" + "source": "https://git.drupalcode.org/project/addtocalendar" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index abf2dd8aa3..221460f81e 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2110,30 +2110,27 @@ }, { "name": "drupal/addtocalendar", - "version": "3.1.0", - "version_normalized": "3.1.0.0", + "version": "3.2.0", + "version_normalized": "3.2.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/addtocalendar.git", - "reference": "8.x-3.1" + "reference": "8.x-3.2" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.1.zip", - "reference": "8.x-3.1", - "shasum": "c384df6017790173908ee7566e2af22ab5234b9d" + "url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.2.zip", + "reference": "8.x-3.2", + "shasum": "b739326d98008f4091f71e0d5d21b5baa93a5dec" }, "require": { - "drupal/core": "*" + "drupal/core": "^8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { - "version": "8.x-3.1", - "datestamp": "1511952790", + "version": "8.x-3.2", + "datestamp": "1591246880", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -2177,7 +2174,7 @@ "description": "Add to calendar button to be used for event page.", "homepage": "https://www.drupal.org/project/addtocalendar", "support": { - "source": "http://cgit.drupalcode.org/addtocalendar" + "source": "https://git.drupalcode.org/project/addtocalendar" } }, { diff --git a/web/modules/addtocalendar/addtocalendar.info.yml b/web/modules/addtocalendar/addtocalendar.info.yml index b55c03665c..4e787fcecf 100644 --- a/web/modules/addtocalendar/addtocalendar.info.yml +++ b/web/modules/addtocalendar/addtocalendar.info.yml @@ -2,12 +2,12 @@ name: Add To Calendar type: module description: 'Add to calendar button to be used for event page.' # version: VERSION -# core: 8.x +core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - - datetime + - drupal:datetime -# Information added by Drupal.org packaging script on 2017-11-29 -version: '8.x-3.1' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-06-04 +version: '8.x-3.2' project: 'addtocalendar' -datestamp: 1511952793 +datestamp: 1591246882 diff --git a/web/modules/addtocalendar/addtocalendar.libraries.yml b/web/modules/addtocalendar/addtocalendar.libraries.yml index e57d6ea544..476bcc27ed 100644 --- a/web/modules/addtocalendar/addtocalendar.libraries.yml +++ b/web/modules/addtocalendar/addtocalendar.libraries.yml @@ -4,6 +4,7 @@ base: '//addtocalendar.com/atc/1.5/atc-base.css': {type: external} js: '//addtocalendar.com/atc/1.5/atc.min.js': { type: external, minified: true } + 'js/addtocalendar.js': {} glow_orange: css: diff --git a/web/modules/addtocalendar/addtocalendar.services.yml b/web/modules/addtocalendar/addtocalendar.services.yml index 07f2a302de..ca410e290b 100644 --- a/web/modules/addtocalendar/addtocalendar.services.yml +++ b/web/modules/addtocalendar/addtocalendar.services.yml @@ -1,5 +1,5 @@ services: addtocalendar.apiwidget: class: Drupal\addtocalendar\AddToCalendarApiWidget - arguments: [] + arguments: ['@config.factory'] diff --git a/web/modules/addtocalendar/includes/addtocalendar.build.inc b/web/modules/addtocalendar/includes/addtocalendar.build.inc index f178a6356b..7ff78a5a94 100644 --- a/web/modules/addtocalendar/includes/addtocalendar.build.inc +++ b/web/modules/addtocalendar/includes/addtocalendar.build.inc @@ -108,7 +108,8 @@ function _addtocalendar_preprocess_field(&$variables) { $class_value = strip_tags($entity->{$field}->end_value); } else { - $class_value = strip_tags(render($entity->get($field)->view(['label' => 'hidden']))); + $view = $entity->get($field)->view(['label' => 'hidden']); + $class_value = strip_tags(render($view)); } break; } diff --git a/web/modules/addtocalendar/includes/addtocalendar.form.inc b/web/modules/addtocalendar/includes/addtocalendar.form.inc index 36e5cf3ea5..c4c578896e 100644 --- a/web/modules/addtocalendar/includes/addtocalendar.form.inc +++ b/web/modules/addtocalendar/includes/addtocalendar.form.inc @@ -42,7 +42,7 @@ function _addtocalendar_build_form($settings, $field_definition) { 'blue' => t('Blue'), 'glow_orange' => t('Glow Orange'), ], - '#default_value' => !empty($settings['addtocalendar_settings']['style']) ? $settings['addtocalendar_settings']['style'] : 'blue', + '#default_value' => !empty($settings['addtocalendar_settings']['style']) ? $settings['addtocalendar_settings']['style'] : 0, ]; $element['addtocalendar_settings']['display_text'] = [ diff --git a/web/modules/addtocalendar/js/addtocalendar.js b/web/modules/addtocalendar/js/addtocalendar.js new file mode 100644 index 0000000000..2023c8fb7b --- /dev/null +++ b/web/modules/addtocalendar/js/addtocalendar.js @@ -0,0 +1,11 @@ +(function ($) { + + 'use strict'; + + Drupal.behaviors.addtocalendar = { + attach: function (context, settings) { + addtocalendar.load(); + } + }; + +})(jQuery); diff --git a/web/modules/addtocalendar/src/AddToCalendarApiWidget.php b/web/modules/addtocalendar/src/AddToCalendarApiWidget.php index 1807ea72aa..e7b8997315 100644 --- a/web/modules/addtocalendar/src/AddToCalendarApiWidget.php +++ b/web/modules/addtocalendar/src/AddToCalendarApiWidget.php @@ -2,6 +2,7 @@ namespace Drupal\addtocalendar; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Datetime\DrupalDateTime; /** @@ -14,17 +15,96 @@ class AddToCalendarApiWidget { * * @var string */ + + /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** + * Style. + * + * @var string + */ protected $atcStyle; + + /** + * DisplayText. + * + * @var string + */ protected $atcDisplayText; + + /** + * Title. + * + * @var string + */ protected $atcTitle; + + /** + * Description. + * + * @var string + */ protected $atcDescription; + + /** + * Location. + * + * @var string + */ protected $atcLocation; + + /** + * Organizer. + * + * @var string + */ protected $atcOrganizer; + + /** + * Orangizer Email. + * + * @var string + */ protected $atcOrganizerEmail; + + /** + * Start Date. + * + * @var string + */ protected $atcDateStart; + + /** + * End Date. + * + * @var string + */ protected $atcDateEnd; + + /** + * Privacy. + * + * @var string + */ protected $atcPrivacy; + + /** + * DataSecure. + * + * @var string + */ protected $atcDataSecure; + + /** + * Timezone. + * + * @var string + */ protected $timeZone; /** @@ -37,7 +117,7 @@ class AddToCalendarApiWidget { /** * Constructs a new AddToCalendarApiWidget object. */ - public function __construct() { + public function __construct(ConfigFactoryInterface $config_factory) { $this->atcStyle = 'blue'; $this->atcDisplayText = 'Add to calendar'; @@ -45,7 +125,8 @@ public function __construct() { $this->atcDescription = 'Some event description'; $this->atcLocation = 'Some event location'; // Fetching site name and site email id. - $config = \Drupal::config('system.site'); + $this->configFactory = $config_factory; + $config = $this->configFactory->getEditable('system.site'); $site_name = $config->get('name'); $site_mail = $config->get('mail'); @@ -55,21 +136,21 @@ public function __construct() { $this->atcDateEnd = 'now'; $this->atcPrivacy = 'public'; $this->atcDataSecure = 'auto'; - $data_calendars = array('iCalendar', + $data_calendars = ['iCalendar', 'Google Calendar', 'Outlook', 'Outlook Online', 'Yahoo! Calendar', - ); + ]; $this->atcDataCalendars = $data_calendars; - $this->timeZone = drupal_get_user_timezone(); + $this->timeZone = date_default_timezone_get(); } /** * Use this function to set values for the widget. */ - public function setWidgetValues($config_values = array()) { + public function setWidgetValues($config_values = []) { foreach ($config_values as $key => $value) { $this->$key = $value; } @@ -89,7 +170,7 @@ public function generateWidget() { // Start building the renderable array. $build['addtocalendar'] = []; - $display_text = t('%text', array('%text' => $this->atcDisplayText)); + $display_text = t('%text', ['%text' => $this->atcDisplayText]); $build['addtocalendar_button'] = [ '#type' => 'html_tag', '#tag' => 'a', diff --git a/web/modules/addtocalendar/src/Plugin/Field/FieldFormatter/AddToCalendar.php b/web/modules/addtocalendar/src/Plugin/Field/FieldFormatter/AddToCalendar.php index 490077b810..bee4325f96 100644 --- a/web/modules/addtocalendar/src/Plugin/Field/FieldFormatter/AddToCalendar.php +++ b/web/modules/addtocalendar/src/Plugin/Field/FieldFormatter/AddToCalendar.php @@ -6,6 +6,11 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\addtocalendar\AddToCalendarApiWidget; +use Drupal\Core\Utility\Token; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'add_to_calendar' formatter. @@ -18,7 +23,67 @@ * } * ) */ -class AddToCalendar extends FormatterBase { +class AddToCalendar extends FormatterBase implements ContainerFactoryPluginInterface { + + + /** + * The entity manager service. + * + * @var \Drupal\addtocalendar\AddToCalendarApiWidget + */ + protected $addToCalendarApiWidget; + + /** + * The token service. + * + * @var \Drupal\Core\Utility\Token + */ + protected $token; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('addtocalendar.apiwidget'), + $container->get('token') + ); + } + + /** + * Construct an AddToCalendar object. + * + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * Defines an interface for entity field definitions. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Any third party settings. + * @param \Drupal\addtocalendar\AddToCalendarApiWidget $add_to_calendar_api_widget + * AddToCalendarApi Widget service. + * @param \Drupal\Core\Utility\Token $token + * Token service. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AddToCalendarApiWidget $add_to_calendar_api_widget, Token $token) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + $this->addToCalendarApiWidget = $add_to_calendar_api_widget; + $this->token = $token; + } /** * {@inheritdoc} @@ -77,7 +142,7 @@ protected function viewValue(FieldItemInterface $item) { $entity_type = $entity->getEntityTypeId(); $settings = $this->fieldDefinition->getSettings(); - $service = \Drupal::service('addtocalendar.apiwidget'); + $service = $this->addToCalendarApiWidget; $config_values = [ 'atcStyle' => $settings['addtocalendar_settings']['style'], 'atcDisplayText' => $this->fieldDefinition->getSetting('on_label'), @@ -92,7 +157,7 @@ protected function viewValue(FieldItemInterface $item) { 'atcDataSecure' => $settings['addtocalendar_settings']['data_secure'], ]; if ($settings['addtocalendar_settings']['data_calendars']) { - $data_calendars = array(); + $data_calendars = []; foreach ($settings['addtocalendar_settings']['data_calendars'] as $key => $set) { if ($set) { $data_calendars[$key] = $key; @@ -116,7 +181,7 @@ protected function viewValue(FieldItemInterface $item) { * * @param array $field_setting * The field setting array. - * @param $entity + * @param object $entity * The entity from which the value is to be returned. * @param array $options * Provide various options usable to override the data value being return @@ -126,10 +191,10 @@ protected function viewValue(FieldItemInterface $item) { * @return string * The textual output generated. */ - public function getProperValue(array $field_setting, $entity, array $options = array()) { + public function getProperValue(array $field_setting, $entity, array $options = []) { $entity_type = $entity->getEntityTypeId(); // Create token service. - $token_service = \Drupal::token(); + $token_service = $this->token; $token_options = [ 'langcode' => $entity->language()->getId(), 'callback' => '', -- GitLab