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 TYPO3v10 support #13

Merged
merged 26 commits into from
Sep 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
56031db
[TASK] Allow installation with TYPO3v10
mbrodala Sep 10, 2020
abbed52
[TASK] Build against TYPO3v10
mbrodala Sep 10, 2020
36d7d1b
[TASK] Replace deprecated $GLOBALS['TSFE']->sys_language_uid access
mbrodala Sep 11, 2020
bda6c33
[TASK] Ignore cross-version errors in PHPStan
mbrodala Sep 11, 2020
cc1646f
[BUGFIX] Fix failing TcaDataCollector unit test
mbrodala Sep 11, 2020
e3af625
[TASK] Reduce usage of $_EXTKEY
mbrodala Sep 11, 2020
c09faa5
[TASK] Use own response object
mbrodala Sep 15, 2020
d7ab78c
[TASK] Move webserver for functional testing to a trait
mbrodala Sep 16, 2020
cc58e4a
[BUGFIX] Wait for webserver to be ready
mbrodala Sep 16, 2020
c3ee6dd
[BUGFIX] Forward prepared TYPO3_* env variables to webserver
mbrodala Sep 16, 2020
fa570f8
[TASK] Add middleware for URI building in TYPO3v9+
mbrodala Sep 16, 2020
cdd8de2
[TASK] Set slugs in indexing test for TYPO3v9+
mbrodala Sep 16, 2020
f2c1d98
[TASK] Skip EidUtility usage if absent in TYPO3v10+
mbrodala Sep 16, 2020
9669869
[TASK] Skip TSFE simulation for record overlays in TYPO3v10+
mbrodala Sep 16, 2020
072e1b9
[TASK] Drop logging from functional test webserver
mbrodala Sep 17, 2020
631c08e
[BUGFIX] Properly create SiteConfiguration in TYPO3v9
mbrodala Sep 17, 2020
d716df8
[BUGFIX] Explicitly stop webserver again
mbrodala Sep 17, 2020
0c70ed7
[BUGFIX] Update expected links in test for TYPO3v9+
mbrodala Sep 17, 2020
d1c6a79
[TASK] Use cross-version setup for sites in tests again
mbrodala Sep 17, 2020
34c273f
[BUGFIX] Fix TSFE booting for TYPO3v9
mbrodala Sep 17, 2020
a15355b
[TASK] Merge AbstractEidLinkBuilder into AbstractLinkBuilder
mbrodala Sep 17, 2020
27691d3
[TASK] Use middleware for link building in TYPO3v9+
mbrodala Sep 17, 2020
80b1558
[TASK] Skip title when building links
mbrodala Sep 17, 2020
d87ce48
[BUGFIX] Flush site configuration caches in TYPO3v9+
mbrodala Sep 17, 2020
d53d86d
[BUGFIX] Always return integer in language ID trait
mbrodala Sep 17, 2020
b0bbb02
[TASK] Ignore extension scanner match for command controller
mbrodala Sep 17, 2020
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
Prev Previous commit
Next Next commit
[TASK] Merge AbstractEidLinkBuilder into AbstractLinkBuilder
  • Loading branch information
mbrodala committed Sep 17, 2020
commit a15355b578ac429ebfd68e84a894b890763b3ce0
128 changes: 0 additions & 128 deletions Classes/LinkBuilder/AbstractEidLinkBuilder.php

This file was deleted.

107 changes: 105 additions & 2 deletions Classes/LinkBuilder/AbstractLinkBuilder.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

use PAGEmachine\Searchable\Configuration\DynamicConfigurationInterface;
use PAGEmachine\Searchable\Service\ConfigurationMergerService;
use PAGEmachine\Searchable\Service\ExtconfService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/*
* This file is part of the PAGEmachine Searchable project.
@@ -11,7 +13,7 @@
/**
* AbstractLinkBuilder
*/
abstract class AbstractLinkBuilder implements DynamicConfigurationInterface
abstract class AbstractLinkBuilder implements LinkBuilderInterface, DynamicConfigurationInterface
{
/**
* DefaultConfiguration
@@ -20,10 +22,18 @@ abstract class AbstractLinkBuilder implements DynamicConfigurationInterface
* @var array
*/
protected static $defaultConfiguration = [
'titleField' => 'title',
'fixedParts' => [],
'languageParam' => 'L',
];

/**
* The default title if the title field is empty
*
* @var string
*/
protected $defaultTitle = 'Link';

/**
* This function will be called by the ConfigurationManager.
* It can be used to add default configuration
@@ -71,6 +81,65 @@ public function createLinkConfiguration($record, $language)
return $linkConfiguration;
}

/**
* Creates links for a batch of records
*
* @param array $records
* @param int $language
* @return array $records
*/
public function createLinksForBatch($records, $language = 0)
{
$configurationArray = [];
$metaField = ExtconfService::getInstance()->getMetaFieldname();

foreach ($records as $key => $record) {
$linkConfiguration = $this->createLinkConfiguration($record, $language);
$linkConfiguration = $this->convertToTypoLinkConfig($linkConfiguration, $record);

$configurationArray[$key] = $linkConfiguration;
}

$links = $this->getFrontendLinks($configurationArray);

foreach ($links as $key => $link) {
$records[$key][$metaField]['renderedLink'] = $link;
$records[$key][$metaField]['linkTitle'] = $this->getLinkTitle($records[$key]);
}

return $records;
}

/**
* Converts builder-specific configuration to TypoLink configuration
* This should be overridden with custom conversion logic
*
* @param array $configuration
* @param array $record
* @return array
*/
public function convertToTypoLinkConfig($configuration, $record)
{
return ['title' => $this->getLinkTitle($record), 'conf' => $configuration];
}

/**
* Fetches the link title
*
* @param array $record
* @return string
*/
protected function getLinkTitle($record = [])
{
$title = $record[$this->config['titleField']];

if ($title == null) {
$title = $this->defaultTitle;
}

return $title;
}

/**
* Adds a language parameter to the link config for translations
*
@@ -84,7 +153,7 @@ protected function addLanguageParameter($linkConfiguration, $language)
if ($language > 0) {
$linkConfiguration['additionalParams'][$this->config['languageParam']] = $language;
}

return $linkConfiguration;
}

@@ -108,4 +177,38 @@ protected function replaceFieldsRecursive($configuration, $record)

return $configuration;
}

protected function getFrontendLinks($configuration)
{
$domain = ExtconfService::getInstance()->getFrontendDomain();

return $this->doRequest($domain, $configuration);
}

/**
* The actual request
*
* @param string $domain
* @param array $configuration
* @return array
*/
protected function doRequest($domain, $configuration)
{
$requestFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\RequestFactory::class);
$response = $requestFactory->request(
$domain,
'POST',
[
'query' => [
'eID' => 'searchable_linkbuilder',
],
'form_params' => [
'configuration' => $configuration,
],
'http_errors' => false,
]
);

return json_decode($response->getBody()->getContents(), true);
}
}
2 changes: 1 addition & 1 deletion Classes/LinkBuilder/FileLinkBuilder.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
* FileLinkBuilder
* Creates a file link (using t3://file) and processes it via eID to a real link
*/
class FileLinkBuilder extends AbstractEidLinkBuilder implements LinkBuilderInterface
class FileLinkBuilder extends AbstractLinkBuilder
{
/**
* DefaultConfiguration
2 changes: 1 addition & 1 deletion Classes/LinkBuilder/LinkBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ interface LinkBuilderInterface
*
* @param array $record
* @param int $language
* @return string
* @return array
*/
public function createLinkConfiguration($record, $language);

2 changes: 1 addition & 1 deletion Classes/LinkBuilder/PageLinkBuilder.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* PageLinkBuilder
* Creates a link configuration array to be passed on to a Fluid link.page ViewHelper
*/
class PageLinkBuilder extends AbstractEidLinkBuilder implements LinkBuilderInterface
class PageLinkBuilder extends AbstractLinkBuilder
{
/**
* @var array
2 changes: 1 addition & 1 deletion Classes/LinkBuilder/TypoLinkBuilder.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* TypoLinkBuilder
* Creates a link based on typolink configuration
*/
class TypoLinkBuilder extends AbstractEidLinkBuilder implements LinkBuilderInterface
class TypoLinkBuilder extends AbstractLinkBuilder
{
/**
* @var array
51 changes: 0 additions & 51 deletions Tests/Unit/LinkBuilder/AbstractEidLinkBuilderTest.php

This file was deleted.

26 changes: 26 additions & 0 deletions Tests/Unit/LinkBuilder/AbstractLinkBuilderTest.php
Original file line number Diff line number Diff line change
@@ -155,4 +155,30 @@ public function unsetsEmptyDynamicFieldsAndUsesFixedPartInstead()

$this->assertArraySubset(['pageUid' => '123'], $linkConfiguration);
}

/**
* @test
*/
public function convertsToTypoLinkConfig()
{
$record = ['title' => 'sometitle'];

$builderConfig = [
'titleField' => 'title',
];

$linkConfig = [
'foo' => 'bar',
];

$typolinkConfig = [
'title' => 'sometitle',
'conf' => ['foo' => 'bar'],
];

$this->linkBuilder = $this->getAccessibleMockForAbstractClass(AbstractLinkBuilder::class, ['config' => $builderConfig]);
$linkConfiguration = $this->linkBuilder->convertToTypoLinkConfig($linkConfig, $record);

$this->assertEquals($typolinkConfig, $linkConfiguration);
}
}