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

Workspace version of record does not accept same content slug due to uniqueInPid #7

Open
jacobsenj opened this issue May 3, 2021 · 3 comments

Comments

@jacobsenj
Copy link

jacobsenj commented May 3, 2021

Like you statet in issue #3 about language versions, there's an issue with the content slug and workspaces (versions of records), too.

I changed the tca of the field to use the slug type in TYPO3 core and added a prefix class with a local composer patch:

--- /dev/null
+++ Classes/FormEngine/SlugPrefix.php
@@ -0,0 +1,14 @@
+<?php
+declare(strict_types = 1);
+
+namespace Sebkln\ContentSlug\FormEngine;
+
+use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSlug;
+
+class SlugPrefix
+{
+    public function getPrefix(array $parameters, TcaSlug $reference): string
+    {
+        return '#';
+    }
+}

--- Configuration/TCA/Overrides/tt_content.php
+++ Configuration/TCA/Overrides/tt_content.php
@@ -7,16 +7,22 @@
         'exclude' => true,
         'label' => 'LLL:EXT:content_slug/Resources/Private/Language/locallang_db.xlf:tt_content.tx_content_slug_fragment',
         'config' => [
-            'type' => 'input',
+            'type' => 'slug',
             'size' => 50,
             'max' => 80,
-            'eval' => 'trim,Sebkln\\ContentSlug\\Evaluation\\FragmentEvaluation,uniqueInPid',
-            'default' => '',
-            'fieldControl' => [
-                'importControl' => [
-                    'renderType' => 'generateFragmentFromHeaderControl'
-                ]
-            ]
+            'generatorOptions' => [
+                'fields' => ['header'],
+                'fieldSeparator' => '-',
+                'replacements' => [
+                    '/' => '-'
+                ],
+            ],
+            'appearance' => [
+                'prefix' => \Sebkln\ContentSlug\FormEngine\SlugPrefix::class . '->getPrefix',
+            ],
+            'fallbackCharacter' => '-',
+            'eval' => 'trim,Sebkln\\ContentSlug\\Evaluation\\FragmentEvaluation,uniqueInPid',
+            'default' => ''
         ],
     ],
     'tx_content_slug_link' => [

Now I'm totally allowed to stay on the defined content slug in the workspace version of the record:

image

Maybe this is of interest for you, too.

Cheers
Jens

@jacobsenj jacobsenj changed the title Workspace version of record does not accept same content-slug due to uniqueInPid Workspace version of record does not accept same content slug due to uniqueInPid May 3, 2021
@jacobsenj
Copy link
Author

I wasn't sure about Sebkln\\ContentSlug\\Evaluation\\FragmentEvaluation in the eval key. Maybe it could be removed after the change to the slug type, too.

@sebkln
Copy link
Owner

sebkln commented May 3, 2021

Thank you for your report. I'll look into Workspaces.

Please note: I did not apply your patch to test the exact behaviour. But you adjusted the TCA close to a former state of this extension. As you can see from the commit message, using the TCA type slug made the fragment field mandatory. This may not be an issue for your project, but I want to keep this field optional.

When I finished the fragment hook for page links, I can revisit the TCA of the fragment field.

@jacobsenj
Copy link
Author

jacobsenj commented May 7, 2021

As you can see from the commit message, using the TCA type slug made the fragment field mandatory. This may not be an issue for your project, but I want to keep this field optional.

Thanks for pointing this out. Indeed, it would add a default-[a-z0-9]{10} value if the content element header would be empty, so i changed it to allow to stay empty if the header is empty using postModifiers in the tca configuration for the field. In my special use case it will make sense to have a slug for each content element where the header field is filled. By having it this way editors are not forced to set the slug initially after adding a content element.

Updated patch, if of interest
--- /dev/null
+++ Classes/FormEngine/Slug.php
@@ -0,0 +1,23 @@
+<?php
+declare(strict_types = 1);
+
+namespace Sebkln\ContentSlug\FormEngine;
+
+use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSlug;
+use TYPO3\CMS\Core\DataHandling\SlugHelper;
+
+class Slug
+{
+    public function getPrefix(array $parameters, TcaSlug $reference): string
+    {
+        return '#';
+    }
+
+    public function modifySlug(array $parameters, SlugHelper $reference): string
+    {
+        if (preg_match('~^default-[a-z0-9]{10}$~s', $parameters['slug'])) {
+            $parameters['slug'] = '';
+        }
+        return $parameters['slug'];
+    }
+}

--- Configuration/TCA/Overrides/tt_content.php
+++ Configuration/TCA/Overrides/tt_content.php
@@ -7,16 +7,25 @@
       'exclude' => true,
       'label' => 'LLL:EXT:content_slug/Resources/Private/Language/locallang_db.xlf:tt_content.tx_content_slug_fragment',
       'config' => [
-            'type' => 'input',
+            'type' => 'slug',
           'size' => 50,
           'max' => 80,
-            'eval' => 'trim,Sebkln\\ContentSlug\\Evaluation\\FragmentEvaluation,uniqueInPid',
-            'default' => '',
-            'fieldControl' => [
-                'importControl' => [
-                    'renderType' => 'generateFragmentFromHeaderControl'
-                ]
-            ]
+            'generatorOptions' => [
+                'fields' => ['header'],
+                'fieldSeparator' => '-',
+                'replacements' => [
+                    '/' => '-'
+                ],
+                'postModifiers' => [
+                    \Sebkln\ContentSlug\FormEngine\Slug::class . '->modifySlug',
+                ],
+            ],
+            'appearance' => [
+                'prefix' => \Sebkln\ContentSlug\FormEngine\Slug::class . '->getPrefix',
+            ],
+            'fallbackCharacter' => '-',
+            'eval' => 'trim,Sebkln\\ContentSlug\\Evaluation\\FragmentEvaluation,uniqueInPid',
+            'default' => ''
       ],
   ],
   'tx_content_slug_link' => [

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants