Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object merge with override for GM and OSM for settings #313

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpstorm.meta.php export-ignore
151 changes: 151 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

/**
* Extend PhpStorms code completion capabilities by providing a meta file
*
* @link https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html
*/

namespace PHPSTORM_META {
expectedArguments(
\TYPO3\CMS\Core\Context\Context::getAspect(),
0,
'date',
'visibility',
'backend.user',
'frontend.user',
'workspace',
'language',
'frontend.preview',
);
override(\TYPO3\CMS\Core\Context\Context::getAspect(), map([
'date' => \TYPO3\CMS\Core\Context\DateTimeAspect::class,
'visibility' => \TYPO3\CMS\Core\Context\VisibilityAspect::class,
'backend.user' => \TYPO3\CMS\Core\Context\UserAspect::class,
'frontend.user' => \TYPO3\CMS\Core\Context\UserAspect::class,
'workspace' => \TYPO3\CMS\Core\Context\WorkspaceAspect::class,
'language' => \TYPO3\CMS\Core\Context\LanguageAspect::class,
'frontend.preview' => \TYPO3\CMS\Frontend\Context\PreviewAspect::class,
]));
expectedArguments(
\TYPO3\CMS\Core\Context\DateTimeAspect::get(),
0,
'timestamp',
'iso',
'timezone',
'full',
'accessTime'
);
expectedArguments(
\TYPO3\CMS\Core\Context\VisibilityAspect::get(),
0,
'includeHiddenPages',
'includeHiddenContent',
'includeDeletedRecords'
);
expectedArguments(
\TYPO3\CMS\Core\Context\UserAspect::get(),
0,
'id',
'username',
'isLoggedIn',
'isAdmin',
'groupIds',
'groupNames'
);
expectedArguments(
\TYPO3\CMS\Core\Context\WorkspaceAspect::get(),
0,
'id',
'isLive',
'isOffline'
);
expectedArguments(
\TYPO3\CMS\Core\Context\LanguageAspect::get(),
0,
'id',
'contentId',
'fallbackChain',
'overlayType',
'legacyLanguageMode',
'legacyOverlayType'
);
expectedArguments(
\TYPO3\CMS\Frontend\Context\PreviewAspect::get(),
0,
'isPreview'
);

expectedArguments(
\Psr\Http\Message\ServerRequestInterface::getAttribute(),
0,
'frontend.user',
'normalizedParams',
'site',
'language',
'routing',
'module',
'moduleData',
'frontend.controller',
'frontend.typoscript',
'frontend.cache.instruction',
'frontend.page.information',
);
override(\Psr\Http\Message\ServerRequestInterface::getAttribute(), map([
'frontend.user' => \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::class,
'normalizedParams' => \TYPO3\CMS\Core\Http\NormalizedParams::class,
'site' => \TYPO3\CMS\Core\Site\Entity\SiteInterface::class,
'language' => \TYPO3\CMS\Core\Site\Entity\SiteLanguage::class,
'routing' => '\TYPO3\CMS\Core\Routing\SiteRouteResult|\TYPO3\CMS\Core\Routing\PageArguments',
'module' => \TYPO3\CMS\Backend\Module\ModuleInterface::class,
'moduleData' => \TYPO3\CMS\Backend\Module\ModuleData::class,
'frontend.controller' => \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
'frontend.typoscript' => \TYPO3\CMS\Core\TypoScript\FrontendTypoScript::class,
'frontend.cache.instruction' => \TYPO3\CMS\Frontend\Cache\CacheInstruction::class,
'frontend.page.information' => \TYPO3\CMS\Frontend\Page\PageInformation::class,
]));

expectedArguments(
\TYPO3\CMS\Core\Http\ServerRequest::getAttribute(),
0,
'frontend.user',
'normalizedParams',
'site',
'language',
'routing',
'module',
'moduleData'
);
override(\TYPO3\CMS\Core\Http\ServerRequest::getAttribute(), map([
'frontend.user' => \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::class,
'normalizedParams' => \TYPO3\CMS\Core\Http\NormalizedParams::class,
'site' => \TYPO3\CMS\Core\Site\Entity\SiteInterface::class,
'language' => \TYPO3\CMS\Core\Site\Entity\SiteLanguage::class,
'routing' => '\TYPO3\CMS\Core\Routing\SiteRouteResult|\TYPO3\CMS\Core\Routing\PageArguments',
'module' => \TYPO3\CMS\Backend\Module\ModuleInterface::class,
'moduleData' => \TYPO3\CMS\Backend\Module\ModuleData::class,
]));

override(\TYPO3\CMS\Core\Routing\SiteMatcher::matchRequest(), type(
\TYPO3\CMS\Core\Routing\SiteRouteResult::class,
\TYPO3\CMS\Core\Routing\RouteResultInterface::class,
)
);

override(\TYPO3\CMS\Core\Routing\PageRouter::matchRequest(), type(
\TYPO3\CMS\Core\Routing\PageArguments::class,
\TYPO3\CMS\Core\Routing\RouteResultInterface::class,
));

override(\Psr\Container\ContainerInterface::get(0), map([
'' => '@',
]));

override(\Psr\EventDispatcher\EventDispatcherInterface::dispatch(0), map([
'' => '@',
]));

override(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(0), map([
'' => '@'
]));
}
5 changes: 5 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
ChangeLog
=========

Version 11.0.3
==============

* BUGFIX: Implement better `extend` function for JavaScript

Version 11.0.2
==============

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[general]
project = maps2 (Maps2)
version = 11.0
release = 11.0.2
release = 11.0.3
copyright = since 2013 by jweiland.net
t3author = Stefan Froemken
description = This TYPO3 extension supports the rendering of a map based on Google Maps or
Expand Down
39 changes: 38 additions & 1 deletion Resources/Private/Build/JavaScript/GoogleMaps2.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,46 @@ function initMap () {
const environment = typeof element.dataset.environment !== 'undefined' ? element.dataset.environment : '{}';
const override = typeof element.dataset.override !== 'undefined' ? element.dataset.override : '{}';

// Pass in the objects to merge as arguments.
// For a deep extend, set the first argument to `true`.
const extend = (...args) => {
let extended = {};
let deep = false;
let i = 0;
let length = args.length;

// Check for deep merge
if (Object.prototype.toString.call(args[0]) === '[object Boolean]') {
deep = args[0];
i++;
}

// Merge the object into the extended object
const merge = function (obj) {
for ( var prop in obj ) {
if ( Object.prototype.hasOwnProperty.call( obj, prop ) ) {
// If deep merge and property is an object, merge properties
if ( deep && Object.prototype.toString.call(obj[prop]) === '[object Object]' ) {
extended[prop] = extend( true, extended[prop], obj[prop] );
} else {
extended[prop] = obj[prop];
}
}
}
};

// Loop through each object and conduct a merge
for ( ; i < length; i++ ) {
var obj = args[i];
merge(obj);
}

return extended;
};

maps2GoogleMaps.push(new GoogleMaps2(
element,
{...JSON.parse(environment), ...JSON.parse(override)}
extend(JSON.parse(environment), JSON.parse(override))
));
});

Expand Down
39 changes: 38 additions & 1 deletion Resources/Private/Build/JavaScript/OpenStreetMap2.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,45 @@ document.querySelectorAll(".maps2").forEach((element) => {
const environment = typeof element.dataset.environment !== 'undefined' ? element.dataset.environment : '{}';
const override = typeof element.dataset.override !== 'undefined' ? element.dataset.override : '{}';

// Pass in the objects to merge as arguments.
// For a deep extend, set the first argument to `true`.
const extend = (...args) => {
let extended = {};
let deep = false;
let i = 0;
let length = args.length;

// Check for deep merge
if (Object.prototype.toString.call(args[0]) === '[object Boolean]') {
deep = args[0];
i++;
}

// Merge the object into the extended object
const merge = function (obj) {
for ( var prop in obj ) {
if ( Object.prototype.hasOwnProperty.call( obj, prop ) ) {
// If deep merge and property is an object, merge properties
if ( deep && Object.prototype.toString.call(obj[prop]) === '[object Object]' ) {
extended[prop] = extend( true, extended[prop], obj[prop] );
} else {
extended[prop] = obj[prop];
}
}
}
};

// Loop through each object and conduct a merge
for ( ; i < length; i++ ) {
var obj = args[i];
merge(obj);
}

return extended;
};

maps2OpenStreetMaps.push(new OpenStreetMap2(
element,
{...JSON.parse(environment), ...JSON.parse(override)}
extend(true, JSON.parse(environment), JSON.parse(override))
));
});
2 changes: 1 addition & 1 deletion Resources/Private/Build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Follow these steps to build fresh JS files:
the `Resources/Public/JavaScript` folder:

```
gulp
./node_modules/.bin/gulp
```
Loading