-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\ContentBlocks\FieldType; | ||
|
||
/** | ||
* @internal Not part of TYPO3's public API. | ||
*/ | ||
final class PassFieldType implements FieldTypeInterface | ||
{ | ||
private mixed $default = ''; | ||
|
||
public static function getName(): string | ||
{ | ||
return 'Pass'; | ||
} | ||
|
||
public static function getTcaType(): string | ||
{ | ||
return 'passthrough'; | ||
} | ||
|
||
public static function isSearchable(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public static function createFromArray(array $settings): PassFieldType | ||
{ | ||
$self = new self(); | ||
$self->default = $settings['default'] ?? $self->default; | ||
return $self; | ||
} | ||
|
||
public function getTca(): array | ||
{ | ||
$config['type'] = self::getTcaType(); | ||
if ($this->default !== '') { | ||
$config['default'] = $this->default; | ||
} | ||
$tca['config'] = $config; | ||
return $tca; | ||
} | ||
|
||
public function getSql(string $column): string | ||
{ | ||
return "`$column` VARCHAR(255) DEFAULT '' NOT NULL"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.. include:: /Includes.rst.txt | ||
.. _field_type_pass: | ||
|
||
==== | ||
Pass | ||
==== | ||
|
||
:php:`type => 'passthrough' // TCA` | ||
|
||
The :yaml:`Pass` type provides a virtual field, which is not visible in the | ||
backend. It is useful for extension logic handling this value independently. | ||
|
||
Settings | ||
======== | ||
|
||
.. confval:: default | ||
:name: pass-default | ||
|
||
:Required: false | ||
:Type: mixed | ||
:Default: '' | ||
|
||
Default value set if a new record is created. | ||
|
||
.. note:: | ||
|
||
This does not work right now in some circumstances. See issue: https://forge.typo3.org/issues/104646 | ||
|
||
Example | ||
======= | ||
|
||
Minimal | ||
------- | ||
|
||
.. code-block:: yaml | ||
name: example/pass | ||
fields: | ||
- identifier: pass | ||
type: Pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\ContentBlocks\Tests\Unit\FieldTypes; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use TYPO3\CMS\ContentBlocks\FieldType\PassFieldType; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
final class PassFieldTypeTest extends UnitTestCase | ||
{ | ||
public static function getTcaReturnsExpectedTcaDataProvider(): iterable | ||
{ | ||
yield 'truthy values' => [ | ||
'config' => [ | ||
'default' => 'foo', | ||
], | ||
'expectedTca' => [ | ||
'config' => [ | ||
'type' => 'passthrough', | ||
'default' => 'foo', | ||
], | ||
], | ||
]; | ||
|
||
yield 'falsy values' => [ | ||
'config' => [ | ||
'default' => 0, | ||
], | ||
'expectedTca' => [ | ||
'config' => [ | ||
'type' => 'passthrough', | ||
'default' => 0, | ||
], | ||
], | ||
]; | ||
} | ||
|
||
#[DataProvider('getTcaReturnsExpectedTcaDataProvider')] | ||
#[Test] | ||
public function getTcaReturnsExpectedTca(array $config, array $expectedTca): void | ||
{ | ||
$fieldConfiguration = PassFieldType::createFromArray($config); | ||
|
||
self::assertSame($expectedTca, $fieldConfiguration->getTca()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters