Skip to content
Snippets Groups Projects
Commit e0f571c5 authored by Michael Lee's avatar Michael Lee
Browse files

Merge branch 'addtocalendar' into lee5151

parents 6ff42d64 3df874ad
No related branches found
No related tags found
No related merge requests found
Showing
with 447 additions and 37 deletions
......@@ -1617,17 +1617,17 @@
},
{
"name": "drupal/addtocalendar",
"version": "3.3.0",
"version": "3.4.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/addtocalendar.git",
"reference": "8.x-3.3"
"reference": "8.x-3.4"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.3.zip",
"reference": "8.x-3.3",
"shasum": "92ed466bc3f23f20384c7a52ff6ff17361666374"
"url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.4.zip",
"reference": "8.x-3.4",
"shasum": "2eac31ff573a257b6032a7d9b84a675b653c0492"
},
"require": {
"drupal/core": "^9.3 || ^10"
......@@ -1635,8 +1635,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-3.3",
"datestamp": "1684784136",
"version": "8.x-3.4",
"datestamp": "1691513479",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -1671,18 +1671,18 @@
},
{
"name": "drupal/addtocalendar",
"version": "3.3.0",
"version_normalized": "3.3.0.0",
"version": "3.4.0",
"version_normalized": "3.4.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/addtocalendar.git",
"reference": "8.x-3.3"
"reference": "8.x-3.4"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.3.zip",
"reference": "8.x-3.3",
"shasum": "92ed466bc3f23f20384c7a52ff6ff17361666374"
"url": "https://ftp.drupal.org/files/projects/addtocalendar-8.x-3.4.zip",
"reference": "8.x-3.4",
"shasum": "2eac31ff573a257b6032a7d9b84a675b653c0492"
},
"require": {
"drupal/core": "^9.3 || ^10"
......@@ -1690,8 +1690,8 @@
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-3.3",
"datestamp": "1684784136",
"version": "8.x-3.4",
"datestamp": "1691513479",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -269,9 +269,9 @@
'dev_requirement' => false,
),
'drupal/addtocalendar' => array(
'pretty_version' => '3.3.0',
'version' => '3.3.0.0',
'reference' => '8.x-3.3',
'pretty_version' => '3.4.0',
'version' => '3.4.0.0',
'reference' => '8.x-3.4',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/addtocalendar',
'aliases' => array(),
......
<?php
/**
* @file
* Hooks and API provided by the "Add To Calendar" module.
*/
use Drupal\Core\Entity\EntityInterface;
/**
* @addtogroup hooks
* @{
*/
/**
* Allows to alter the field's data comes from an entity.
*
* @param $value
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function hook_addtocalendar_field_alter(&$value, EntityInterface $entity) {
// Here we have full access to $value.
$value = 'This field was altered.';
}
/**
* Allows to alter the field's data comes from an entity by field name.
*
* @param $value
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function hook_addtocalendar_field_FIELD_NAME_alter(&$value, EntityInterface $entity) {
// Here we have full access to $value.
$value = 'This field was altered.';
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -6,7 +6,7 @@ core_version_requirement: ^9.3 || ^10
dependencies:
- drupal:datetime
# Information added by Drupal.org packaging script on 2023-05-22
version: '8.x-3.3'
# Information added by Drupal.org packaging script on 2023-08-08
version: '8.x-3.4'
project: 'addtocalendar'
datestamp: 1684784138
datestamp: 1691513481
<?php
/**
* @file
* Update hooks, etc.
*/
/**
* #3092765: Re-save addtocalendar field config with new schema.
*/
function addtocalendar_update_9200() {
$fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_type' => 'add_to_calendar_field']);
foreach ($fields as $field) {
$field->save();
}
}
<?php
/**
* @file
* Post-update functions for addtocalendar module.
*/
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
/**
* #3092765: Re-save third party settings with new schema.
*/
function addtocalendar_post_update_third_party_settings(&$sandbox) {
$config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
$formatter_callback = function (EntityDisplayInterface $display) {
foreach ($display->getComponents() as $field_name => $component) {
if (isset($component['third_party_settings']['addtocalendar'])) {
// Note that normally the pattern is to use a $needs_save variable.
// However, the ConfigEntityUpdater::update() method ends up saving
// with "trusted data" such that the schema is not used to cast values.
// Using the schema to cast values is all we want to do here!
$display->save();
break;
}
}
return NULL;
};
$config_entity_updater->update($sandbox, 'entity_view_display', $formatter_callback);
}
addtocalendar_show: 0
addtocalendar_show: '0'
style: blue
display_text: 'Add to Calendar'
atc_title: 'Title'
......
......@@ -33,3 +33,92 @@ addtocalendar.settings:
delta:
type: integer
label: 'AddToCalendar button visibility for a particular date field'
addtocalendar_setting:
type: mapping
mapping:
field:
type: string
label: 'Field to be used'
tokenized:
type: string
label: 'Static/Tokenized Content'
addtocalendar_settings:
type: mapping
mapping:
addtocalendar_show:
type: string
label: 'Show Add to Calendar'
style:
type: string
label: 'Select Style'
display_text:
type: text
label: 'Display Text'
translatable: true
atc_title:
type: addtocalendar_setting
atc_description:
type: addtocalendar_setting
atc_location:
type: addtocalendar_setting
atc_organizer:
type: addtocalendar_setting
atc_organizer_email:
type: addtocalendar_setting
atc_date_start:
type: addtocalendar_setting
atc_date_end:
type: addtocalendar_setting
atc_privacy:
type: string
label: 'Privacy of the event'
data_secure:
type: string
label: 'Security level'
data_calendars:
type: mapping
mapping:
Google Calendar:
type: string
label: 'Google Calendar'
Outlook Online:
type: string
label: 'Outlook Online'
iCalendar:
type: string
label: 'iCalendar'
Outlook:
type: string
label: 'Outlook'
Yahoo! Calendar:
type: string
label: 'Yahoo! Calendar'
field.field_settings.add_to_calendar_field:
type: field.field_settings.boolean
label: 'Add to calendar field settings'
mapping:
addtocalendar_show:
type: integer
label: 'Show Add to Calendar'
addtocalendar_settings:
type: addtocalendar_settings
field.value.add_to_calendar_field:
type: mapping
label: 'Default value'
mapping:
value:
type: string
label: 'Show Add to Calendar'
field.formatter.third_party.addtocalendar:
type: mapping
mapping:
addtocalendar_show:
type: integer
label: 'Show Add to Calendar'
addtocalendar_settings:
type: addtocalendar_settings
......@@ -135,7 +135,7 @@ function _addtocalendar_build_form($settings, $field_definition) {
'public' => t('Public'),
'private' => t('Private'),
],
'#description' => t('Use public for free access to event information from any places. User private if the event is closed to public access.'),
'#description' => t('Use "Public" for free access to event information from any places. Use "Private" if the event is closed to public access.'),
'#default_value' => !empty($settings['addtocalendar_settings']['atc_privacy']) ? $settings['addtocalendar_settings']['atc_privacy'] : 'public',
];
$element['addtocalendar_settings']['data_secure'] = [
......
......@@ -2,6 +2,7 @@
namespace Drupal\addtocalendar\Plugin\Field\FieldFormatter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
......@@ -26,7 +27,6 @@
*/
class AddToCalendar extends FormatterBase implements ContainerFactoryPluginInterface {
/**
* The entity manager service.
*
......@@ -41,6 +41,13 @@ class AddToCalendar extends FormatterBase implements ContainerFactoryPluginInter
*/
protected $token;
/**
* The ModuleHandler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The renderer service.
*
......@@ -62,7 +69,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration['third_party_settings'],
$container->get('addtocalendar.apiwidget'),
$container->get('token'),
$container->get('renderer')
$container->get('renderer'),
$container->get('module_handler')
);
}
......@@ -89,8 +97,10 @@ public static function create(ContainerInterface $container, array $configuratio
* Token service.
* @param \Drupal\Core\Render\RendererInterface|null $renderer
* The renderer service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* ModuleHandler 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, RendererInterface $renderer = NULL) {
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, RendererInterface $renderer = NULL, ModuleHandlerInterface $module_handler = NULL) {
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;
......@@ -101,6 +111,13 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
else {
$this->renderer = $renderer;
}
if (is_null($module_handler)) {
@trigger_error('Calling AddToCalendar::_construct() without the $module_handler argument is deprecated and the argument will be required in a future release.', E_USER_DEPRECATED);
$this->moduleHandler = \Drupal::service('module_handler');
}
else {
$this->moduleHandler = $module_handler;
}
}
/**
......@@ -164,13 +181,13 @@ protected function viewValue(FieldItemInterface $item) {
$config_values = [
'atcStyle' => $settings['addtocalendar_settings']['style'],
'atcDisplayText' => $this->fieldDefinition->getSetting('on_label'),
'atcTitle' => $this->getProperValue($settings['addtocalendar_settings']['atc_title'], $entity),
'atcDescription' => $this->getProperValue($settings['addtocalendar_settings']['atc_description'], $entity),
'atcLocation' => $this->getProperValue($settings['addtocalendar_settings']['atc_location'], $entity),
'atcDateStart' => $this->getProperValue($settings['addtocalendar_settings']['atc_date_start'], $entity, ['use_raw_value' => TRUE]),
'atcDateEnd' => $this->getProperValue($settings['addtocalendar_settings']['atc_date_end'], $entity, ['use_raw_value' => TRUE, 'end_date' => TRUE]),
'atcOrganizer' => $this->getProperValue($settings['addtocalendar_settings']['atc_organizer'], $entity),
'atcOrganizerEmail' => $this->getProperValue($settings['addtocalendar_settings']['atc_organizer_email'], $entity),
'atcTitle' => $this->getProperValue($settings['addtocalendar_settings']['atc_title'], $entity, [], 'title'),
'atcDescription' => $this->getProperValue($settings['addtocalendar_settings']['atc_description'], $entity, [], 'description'),
'atcLocation' => $this->getProperValue($settings['addtocalendar_settings']['atc_location'], $entity, [], 'location'),
'atcDateStart' => $this->getProperValue($settings['addtocalendar_settings']['atc_date_start'], $entity, ['use_raw_value' => TRUE], 'date_start'),
'atcDateEnd' => $this->getProperValue($settings['addtocalendar_settings']['atc_date_end'], $entity, ['use_raw_value' => TRUE, 'end_date' => TRUE], 'date_end'),
'atcOrganizer' => $this->getProperValue($settings['addtocalendar_settings']['atc_organizer'], $entity, [], 'organizer'),
'atcOrganizerEmail' => $this->getProperValue($settings['addtocalendar_settings']['atc_organizer_email'], $entity, [], 'organizer_email'),
'atcPrivacy' => $settings['addtocalendar_settings']['atc_privacy'],
'atcDataSecure' => $settings['addtocalendar_settings']['data_secure'],
];
......@@ -205,11 +222,13 @@ protected function viewValue(FieldItemInterface $item) {
* Provide various options usable to override the data value being return
* use 'use_raw_value' to return stored value in database.
* use 'end_date' in case of date range fields.
* @param string $field_setting_name
* The field name.
*
* @return string
* The textual output generated.
*/
public function getProperValue(array $field_setting, $entity, array $options = []) {
public function getProperValue(array $field_setting, $entity, array $options = [], string $field_setting_name = '') {
$entity_type = $entity->getEntityTypeId();
// Create token service.
$token_service = $this->token;
......@@ -243,8 +262,18 @@ public function getProperValue(array $field_setting, $entity, array $options = [
}
break;
}
return $value;
// Alter a value of the field using hook_addtocalendar_field_alter()
// and/or hook_addtocalendar_field_FIELD_NAME_alter() hook.
// @see addtocalendar.api.php
$variables = [
'entity' => $entity,
'setting_name' => $field_setting_name,
];
$this->moduleHandler->alter('addtocalendar_field_' . $field_setting['field'], $value, $variables);
$this->moduleHandler->alter('addtocalendar_field', $value, $variables, $field_setting['field']);
return $value;
}
}
......@@ -27,7 +27,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#type' => 'checkbox',
'#default_value' => !empty($items[0]->value),
];
$element['value']['#title'] = 'Show add to calendar widget';
$element['value']['#title'] = $this->t('Show add to calendar widget');
$element['value']['#title_display'] = 'after';
return $element;
}
......
name: Add To Calendar Test
type: module
description: 'Test support for addtocalendar module.'
core_version_requirement: ^9.3 || ^10
dependencies:
- addtocalendar:addtocalendar
- drupal:node
- drupal:text
# Information added by Drupal.org packaging script on 2023-08-08
version: '8.x-3.4'
project: 'addtocalendar'
datestamp: 1691513481
<?php
/**
* Prevent external js from being requested.
*
* Implements hook_library_info_alter().
*/
function addtocalendar_test_library_info_alter(&$libraries, $extension) {
if ($extension === 'addtocalendar') {
$libraries['base']['js'] = [];
}
}
langcode: en
status: true
dependencies:
config:
- field.field.node.page.body
- field.field.node.page.field_addtocalendar
- field.field.node.page.field_date
- node.type.page
module:
- addtocalendar
- datetime
- user
id: node.page.default
targetEntityType: node
bundle: page
mode: default
content:
field_addtocalendar:
type: add_to_calendar
label: above
settings: { }
third_party_settings: { }
weight: 0
region: content
field_date:
type: datetime_plain
label: above
weight: 1
region: content
settings:
timezone_override: ''
third_party_settings:
addtocalendar:
addtocalendar_show: 1
addtocalendar_settings:
style: '0'
display_text: 'Add to Calendar'
atc_title:
field: title
tokenized: Title
atc_description:
field: body
tokenized: Description
atc_location:
field: token
tokenized: 'The Internet'
atc_organizer:
field: token
tokenized: '[site:name]'
atc_organizer_email:
field: token
tokenized: '[node:title]'
atc_date_end:
field: token
tokenized: ''
atc_privacy: public
data_secure: auto
data_calendars:
'Google Calendar': 'Google Calendar'
Outlook: Outlook
iCalendar: '0'
'Outlook Online': '0'
'Yahoo! Calendar': '0'
hidden:
body: true
links: true
langcode: en
status: true
dependencies:
config:
- field.storage.node.body
- node.type.page
module:
- text
id: node.page.body
field_name: body
entity_type: node
bundle: page
label: Body
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
display_summary: false
required_summary: false
allowed_formats: { }
field_type: text_with_summary
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_addtocalendar
- node.type.page
module:
- addtocalendar
id: node.page.field_addtocalendar
field_name: field_addtocalendar
entity_type: node
bundle: page
label: addtocalendar
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
on_label: 'Add to Calendar'
off_label: 'Add to Calendar Disabled'
addtocalendar_show: 1
addtocalendar_settings:
style: '0'
atc_title:
field: title
tokenized: Title
atc_description:
field: body
tokenized: Description
atc_location:
field: token
tokenized: 'The Internet'
atc_organizer:
field: token
tokenized: '[site:name]'
atc_organizer_email:
field: token
tokenized: '[node:title]'
atc_date_start:
field: field_date
tokenized: ''
atc_date_end:
field: token
tokenized: ''
atc_privacy: public
data_secure: auto
data_calendars:
'Google Calendar': 'Google Calendar'
Outlook: Outlook
iCalendar: '0'
'Outlook Online': '0'
'Yahoo! Calendar': '0'
field_type: add_to_calendar_field
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_date
- node.type.page
module:
- datetime
id: node.page.field_date
field_name: field_date
entity_type: node
bundle: page
label: Date
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: datetime
langcode: en
status: true
dependencies:
module:
- addtocalendar
- node
id: node.field_addtocalendar
field_name: field_addtocalendar
entity_type: node
type: add_to_calendar_field
settings: { }
module: addtocalendar
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
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