diff --git a/composer.json b/composer.json index d02806bc3db87d23a4c541a68f841b7ca26c16de..fcdc5f8e2e4f5155ce7c241c553b77c199ccb29f 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 cf0e283fd2db8dcfebc772c5dd8e64ed4bfe7ee4..c17364faffffa4e0adb1824b7639b9580309b3b0 100644 --- a/composer.lock +++ b/composer.lock @@ -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 398f19841bfcbd8fb50c0cd182262edfa6b4eeba..bcbbfd79f6484783955494128a8e0244f5c0478f 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 b55c03665c3cc88aac86a72bca3e45593c6efaca..4e787fcecfef405a729655d9a9d829c93039dcde 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 e57d6ea544c12c31c23d29ee11271df0e460b5eb..476bcc27edaaa541d9e8c0b54b23e6ac7d97c79e 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 07f2a302dec487eed7a39d123b4aab61c2df072c..ca410e290b846ff2bbe3b7c5c51873bcdb07f5d7 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 f178a6356ba3bf76943a209ec1441949a16cf15a..7ff78a5a946216f397bb197704f0388962f48ddc 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 36e5cf3ea5a9055920e18960da8f3982104def05..c4c578896eef2127a84dd62eacc86e247e386632 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 0000000000000000000000000000000000000000..2023c8fb7bee1becbba5310fa1f4af58a60c7219 --- /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 1807ea72aa2828f2621fd56c7d6a43ddebb58ba0..e7b8997315d26da771af5b1fbeb758a4a2468978 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 490077b810d3139c938b6fa8a9a0b33be5a10381..bee4325f96858819ac94e13951b76e39679e1e7f 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' => '',