Skip to content

Commit

Permalink
[FEATURE] Add argument "fields" to editRecord ViewHelpers
Browse files Browse the repository at this point in the history
The <be:link.editRecord> and <be:url.editRecord> now have an option
argument "fields" which can be used to limit the edit form to only
these fields (instead of the entire record).

The fields should be passed in a comma separated list.

Resolves: #89644
Releases: master
Change-Id: I28913c072578aacd1da95c3bacebea35f8958bac
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62298
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Siepmann <coding@daniel-siepmann.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
sypets authored and bmack committed Dec 31, 2019
1 parent ba6219d commit 40fd85f
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
* Link to edit page uid=3 and then return back to the BE module "web_MyextensionList"::
*
* <be.link.editRecord uid="3" table="pages" returnUrl="{f:be.uri(route: 'web_MyextensionList')}">
*
* Link to edit only the fields title and subtitle of page uid=42 and return to foo/bar::
*
* <be:link.editRecord uid="42" table="pages" fields="title,subtitle" returnUrl="foo/bar">
* Edit record
* </be:link.editRecord>
*
* Output::
*
* <a href="/typo3/index.php?route=/record/edit&edit[pages][42]=edit&returnUrl=foo/bar&columnsOnly=title,subtitle">
* Edit record
* </a>
*/
class EditRecordViewHelper extends AbstractTagBasedViewHelper
{
Expand All @@ -56,6 +68,7 @@ public function initializeArguments()
$this->registerUniversalTagAttributes();
$this->registerArgument('uid', 'int', 'uid of record to be edited', true);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('fields', 'string', 'Edit only these fields (comma separated list)', false);
$this->registerArgument('returnUrl', 'string', 'return to this URL after closing the edit dialog', false, '');
}

Expand All @@ -76,6 +89,9 @@ public function render(): string
'edit' => [$this->arguments['table'] => [$this->arguments['uid'] => 'edit']],
'returnUrl' => $this->arguments['returnUrl']
];
if ($this->arguments['fields'] ?? false) {
$params['columnsOnly'] = $this->arguments['fields'];
}
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uri = (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
$this->tag->addAttribute('href', $uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
* <be:uri.editRecord uid="42" table="a_table" returnUrl="foo/bar" />
*
* ``/typo3/index.php?route=/record/edit&edit[a_table][42]=edit&returnUrl=foo/bar``
*
* URI to the edit record action: edit only the fields title and subtitle of
* page uid=42 and return to foo/bar::
*
* <be:uri.editRecord uid="42" table="pages" fields="title,subtitle" returnUrl="foo/bar" />
*
* ``<a href="/typo3/index.php?route=/record/edit&edit[pages][42]=edit&returnUrl=foo/bar&columnsOnly=title,subtitle">``
*/
class EditRecordViewHelper extends AbstractViewHelper
{
Expand All @@ -46,6 +53,7 @@ public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'uid of record to be edited, 0 for creation', true);
$this->registerArgument('table', 'string', 'target database table', true);
$this->registerArgument('fields', 'string', 'Edit only these fields (comma separated list)', false);
$this->registerArgument('returnUrl', 'string', '', false, '');
}

Expand All @@ -70,6 +78,9 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
'edit' => [$arguments['table'] => [$arguments['uid'] => 'edit']],
'returnUrl' => $arguments['returnUrl']
];
if ($arguments['fields'] ?? false) {
$params['columnsOnly'] = $arguments['fields'];
}
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
return (string)$uriBuilder->buildUriFromRoute('record_edit', $params);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
<be:link.editRecord uid="43" table="c_table" fields="canonical_url">edit record c_table:42</be:link.editRecord>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
<be:link.editRecord uid="43" table="c_table" fields="canonical_url,title">edit record c_table:42</be:link.editRecord>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
<be:uri.editRecord uid="43" table="c_table" fields="canonical_url">edit record c_table:43</be:uri.editRecord>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers">
<be:uri.editRecord uid="43" table="c_table" fields="canonical_url,title">edit record c_table:43</be:uri.editRecord>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ public function renderReturnsValidLinkWithReturnUrl()
self::assertStringContainsString('returnUrl=foo/bar', $result);
}

/**
* @test
*/
public function renderReturnsValidLinkWithField()
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:backend/Tests/Functional/ViewHelpers/Fixtures/Link/EditRecordViewHelper/WithUidTableAndField.html');
$result = urldecode($view->render());

self::assertStringContainsString('route=/record/edit', $result);
self::assertStringContainsString('edit[c_table][43]=edit', $result);
self::assertStringContainsString('columnsOnly=canonical_url', $result);
}

/**
* @test
*/
public function renderReturnsValidLinkWithFields()
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:backend/Tests/Functional/ViewHelpers/Fixtures/Link/EditRecordViewHelper/WithUidTableAndFields.html');
$result = urldecode($view->render());

self::assertStringContainsString('route=/record/edit', $result);
self::assertStringContainsString('edit[c_table][43]=edit', $result);
self::assertStringContainsString('columnsOnly=canonical_url,title', $result);
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ public function renderReturnsValidLinkWithReturnUrl()
self::assertStringContainsString('returnUrl=foo/bar', $result);
}

/**
* @test
*/
public function renderReturnsValidLinkWithField()
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:backend/Tests/Functional/ViewHelpers/Fixtures/Uri/EditRecordViewHelper/WithUidTableAndField.html');
$result = urldecode($view->render());

self::assertStringContainsString('route=/record/edit', $result);
self::assertStringContainsString('edit[c_table][43]=edit', $result);
self::assertStringContainsString('columnsOnly=canonical_url', $result);
}

/**
* @test
*/
public function renderReturnsValidLinkWithFields()
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:backend/Tests/Functional/ViewHelpers/Fixtures/Uri/EditRecordViewHelper/WithUidTableAndFields.html');
$result = urldecode($view->render());

self::assertStringContainsString('route=/record/edit', $result);
self::assertStringContainsString('edit[c_table][43]=edit', $result);
self::assertStringContainsString('columnsOnly=canonical_url,title', $result);
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. include:: ../../Includes.txt

==========================================================================
Feature: #89644 - Add optional argument "fields" to editRecord ViewHelpers
==========================================================================

See :issue:`89644`

Description
===========

An optional argument "fields" is added to the uri.editRecord and link.editRecord ViewHelper.
This can contain the names of one or more database fields (comma separated).

If the argument "fields" is set, FormEngine creates a form to edit only these fields.


Impact
======

This ViewHelper passes the value given in the `fields` argument to the backend route
'/record/edit` as `columnsOnly` argument.

The functionality for `columnsOnly` already existed for the backend route
`/record/edit` before this patch.

Example
=======

Create a link to edit the `tt_content.bodytext` field of record with uid 42:

.. code-block:: xml
<be:link.editRecord uid="42" table="tt_content" fields="bodytext" returnUrl="foo/bar">
Edit record
</be:link.editRecord>
Output:

.. code-block:: html


<a href="/typo3/index.php?route=/record/edit&edit[tt_content][42]=edit&returnUrl=foo/bar&columnsOnly=bodytext">
Edit record
</a>



.. index:: Fluid, ext:backend

0 comments on commit 40fd85f

Please sign in to comment.