Skip to content
Draft
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ This would end up in your DCA being automatically modified the following way:
1. Clear the project's cache (`<project_dir>/var/cache`).
1. Update the database. The new fields should be created now.

## Twig functions

The following Twig functions are available:

### `mf_value`
This function returns the value of a translatable field for the current language. If the field is not translated, it returns
the value of the fallback language.

```twig
{{ mf_value([field], [entity](, [fallback](, [language]))) }}

# Parameters:
# - field (string): the name of the field to get the value for
# - entity (Model|array): the entity to get the value for (either the model or and an array with the table name and the id of the entity)
# - fallback (string): whether to return the value of the fallback language if the field is not translated (optional, defaults to empty string)
# - language (string): the language to get the value for (optional, defaults to the current language)

# Example:
{{ mf_value('position', ['tl_member', member.id]) }}
{{ mf_value('position', memberModel) }}
{{ mf_value('position', memberModel, 'Employee', 'en') }}
```


## Insert tags

The following new insert tags are available. These take into account the translated jumpTo url and alias.
Expand Down
2 changes: 1 addition & 1 deletion assets/img/pencil-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/img/pencil.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/js/contao-multilingual-fields-bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('../scss/contao-multilingual-fields-bundle.be.scss');
import '../scss/contao-multilingual-fields-bundle.be.scss';

function moveEditButton() {
let widget = document.getElementById('mf_language_edit_switch_button_widget');
Expand Down
37 changes: 19 additions & 18 deletions assets/scss/contao-multilingual-fields-bundle.be.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'mixins/readonly';
@use 'mixins/readonly' as readonly;

.tl_tbox.nolegend {
#mf_language_edit_switch_button_widget {
Expand Down Expand Up @@ -31,11 +31,20 @@
}

#mf_language_edit_switch_button {
float: left;
padding: 1px 0 1px 23px;
background-position: left center;
background-color: transparent;
background-position: 0;
background-repeat: no-repeat;
background-size: contain;
border: none;
display: inline-block;
margin-left: 0px;
padding: 3px 0 3px 23px;

float: left;

//padding: 1px 0 1px 23px;
//background-position: left center;
//background-repeat: no-repeat;
//background-size: contain;

background-image: url(../img/pencil.svg);

Expand All @@ -47,13 +56,13 @@
// readonly controls
.tl_chosen, select, .tl_submit {
&.readonly, .readonly & {
@include readonly-widget();
@include readonly.readonly-widget();
}
}

.widget.readonly {
.tl_metawizard .tl_text, .tl_select, .mce-tinymce {
@include readonly-widget();
@include readonly.readonly-widget();
}

.mce-tinymce {
Expand All @@ -63,14 +72,6 @@
}
}

// checkboxes
.translate-checkbox {
margin-bottom: 3.5rem;

& + [id^="sub_"] > .widget {
margin-top: -3.5rem;
margin-bottom: 3.5rem;
clear: both;
float: left;
}
}
fieldset.tl_box > .widget.mf-origin-field:not(:first-of-type) {
padding-top: 2rem;
}
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"issues": "https://github.com/heimrichhannot/contao-multilingual-fields-bundle/issues"
},
"require": {
"php": "^7.4 || ^8.0",
"contao/core-bundle": "^4.9",
"heimrichhannot/contao-utils-bundle": "^2.241",
"symfony/config": "^4.4 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0"
"php": "^8.2",
"contao/core-bundle": "^5.3",
"heimrichhannot/contao-utils-bundle": "^3.0",
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 12 additions & 3 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
services:
HeimrichHannot\MultilingualFieldsBundle\:
resource: '../src/{EventListener,Util}/*'
public: true
_defaults:
autowire: true

HeimrichHannot\MultilingualFieldsBundle\:
resource: '../src/{EventListener,Twig,Util}/*'
autoconfigure: true
bind:
$bundleConfig: '%huh_multilingual_fields%'

HeimrichHannot\MultilingualFieldsBundle\EventListener\DataContainer\:
resource: '../src/EventListener/DataContainer/*'
autoconfigure: true
public: true

HeimrichHannot\MultilingualFieldsBundle\Multilingual\TableBuilder: ~
6 changes: 4 additions & 2 deletions contao/languages/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
/*
* Misc
*/
$lang['mf_editLanguages'] = '<img src="system/themes/flexible/icons/edit.svg"> Edit languages';
$lang['mf_closeEditLanguages'] = '<img src="system/themes/flexible/icons/back.svg"> Close language editor';
$lang['mf_editLanguages'] = 'Edit languages';
$lang['mf_closeEditLanguages'] = 'Close language editor';
$lang['mf_translateField'][0] = 'Translate (%s)';
$lang['mf_translateField'][1] = 'Click this option in order to translate the field for the given language.';
$lang['mf_language'][0] = 'Restrict to language (empty = always shown)';
$lang['mf_language'][1] = 'Select the language that must be given in order for the content element to be displayed.';
72 changes: 36 additions & 36 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php
//
//declare(strict_types=1);
//
//use PhpCsFixer\Fixer\Basic\BracesPositionFixer;
//use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
//use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
//use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
//use Symplify\EasyCodingStandard\Config\ECSConfig;
//
//return ECSConfig::configure()
// ->withPaths([
// __DIR__ . '/src',
// // __DIR__ . '/contao',
//
// ])
//
// // add a single rule
// ->withRules([
// NoUnusedImportsFixer::class,
// BracesPositionFixer::class,
// ])
// // add sets - group of rules
// ->withPreparedSets(
// arrays: true,
// comments: true,
// docblocks: true,
// spaces: true,
// namespaces: true,
// )
// ->withPhpCsFixerSets(symfony: true)
// ->withSkip([
// NotOperatorWithSuccessorSpaceFixer::class,
// MethodChainingIndentationFixer::class => [
// '*/DependencyInjection/Configuration.php',
// ],
// ]);

declare(strict_types=1);

use PhpCsFixer\Fixer\Basic\BracesPositionFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
// __DIR__ . '/contao',

])

// add a single rule
->withRules([
NoUnusedImportsFixer::class,
BracesPositionFixer::class,
])
// add sets - group of rules
->withPreparedSets(
arrays: true,
comments: true,
docblocks: true,
spaces: true,
namespaces: true,
)
->withPhpCsFixerSets(symfony: true)
->withSkip([
NotOperatorWithSuccessorSpaceFixer::class,
MethodChainingIndentationFixer::class => [
'*/DependencyInjection/Configuration.php',
],
]);
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"@symfony/webpack-encore": "^1.1",
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"webpack": "^5.72.0",
"webpack-cli": "^5.0.1",
"@symfony/webpack-encore": "^5.0",
"sass": "^1.32.8",
"sass-loader": "^11.0.0"
"sass-loader": "^16.0.1"
},
"scripts": {
"build-dev": "yarn encore dev",
Expand Down
8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
parameters:
level: 1
level: 2
paths:
- src
# - contao
# universalObjectCratesClasses:
# - Contao\Model
- contao
universalObjectCratesClasses:
- Contao\Model
# - Contao\Template
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
2 changes: 1 addition & 1 deletion public/assets/contao-multilingual-fields-bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/assets/contao-multilingual-fields-bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/assets/images/pencil-off.1f8c3c00.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/assets/images/pencil-off.a6bd717c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/assets/images/pencil.d40bcf51.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/assets/images/pencil.e8555421.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions public/assets/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"bundles/heimrichhannotmultilingualfields/assets/contao-multilingual-fields-bundle.css": "/bundles/heimrichhannotmultilingualfields/assets/contao-multilingual-fields-bundle.css",
"bundles/heimrichhannotmultilingualfields/assets/contao-multilingual-fields-bundle.js": "/bundles/heimrichhannotmultilingualfields/assets/contao-multilingual-fields-bundle.js",
"bundles/heimrichhannotmultilingualfields/assets/images/pencil-off.svg": "/bundles/heimrichhannotmultilingualfields/assets/images/pencil-off.ba7989e0.svg",
"bundles/heimrichhannotmultilingualfields/assets/images/pencil.svg": "/bundles/heimrichhannotmultilingualfields/assets/images/pencil.33ceff4e.svg"
"bundles/heimrichhannotmultilingualfields/assets/images/pencil-off.svg": "/bundles/heimrichhannotmultilingualfields/assets/images/pencil-off.a6bd717c.svg",
"bundles/heimrichhannotmultilingualfields/assets/images/pencil.svg": "/bundles/heimrichhannotmultilingualfields/assets/images/pencil.e8555421.svg"
}
26 changes: 14 additions & 12 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
// __DIR__ . '/contao',

__DIR__ . '/contao',
])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
# In Vorbereitung für PHP 8.4:
ExplicitNullableParamTypeRector::class
ExplicitNullableParamTypeRector::class
])

->withImportNames(
importShortClasses: false,
removeUnusedImports: true
removeUnusedImports: true,
)
->withAttributesSets(
all: true,
)
->withComposerBased(
twig: true,
doctrine: true,
symfony: true,
)
->withSets([
LevelSetList::UP_TO_PHP_74,
SymfonySetList::SYMFONY_44,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
// # Erst mit Symfony 6 (Contao 5) nutzen:
// // SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
ContaoLevelSetList::UP_TO_CONTAO_49,
LevelSetList::UP_TO_PHP_82,
ContaoLevelSetList::UP_TO_CONTAO_53,
ContaoSetList::FQCN,
// ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES,
ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);
14 changes: 1 addition & 13 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,25 @@
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Config\ConfigInterface;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use HeimrichHannot\MultilingualFieldsBundle\HeimrichHannotMultilingualFieldsBundle;
use MadeYourDay\RockSolidCustomElements\RockSolidCustomElementsBundle;
use Symfony\Component\Config\Loader\LoaderInterface;

class Plugin implements BundlePluginInterface, ConfigPluginInterface
{
/**
* Gets a list of autoload configurations for this bundle.
*
* @return ConfigInterface[]
*/
public function getBundles(ParserInterface $parser): array
{
$loadAfter = [
// @phpstan-ignore class.notFound
RockSolidCustomElementsBundle::class,
ContaoCoreBundle::class,
];

return [
BundleConfig::create(HeimrichHannotMultilingualFieldsBundle::class)
->setLoadAfter($loadAfter)
->setLoadAfter($loadAfter),
];
}

/**
* Allows a plugin to load container configuration.
*/
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig): void
{
$loader->load('@HeimrichHannotMultilingualFieldsBundle/config/services.yaml');
Expand Down
Loading