Skip to content
Snippets Groups Projects
Commit de6579a6 authored by Brian Canini's avatar Brian Canini
Browse files

Merge branch 'addtocalendar' into module-updates-rc

parents 325e5a38 9ee561cf
No related branches found
No related tags found
No related merge requests found
......@@ -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"
}
},
{
......
......@@ -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"
}
},
{
......
......@@ -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
......@@ -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:
......
services:
addtocalendar.apiwidget:
class: Drupal\addtocalendar\AddToCalendarApiWidget
arguments: []
arguments: ['@config.factory']
......@@ -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;
}
......
......@@ -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'] = [
......
(function ($) {
'use strict';
Drupal.behaviors.addtocalendar = {
attach: function (context, settings) {
addtocalendar.load();
}
};
})(jQuery);
......@@ -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',
......
......@@ -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' => '',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment