TYPO3 Logo
TYPO3 Explained
Release: 6.2

Loading data.

  • Introduction
  • Extension Architecture
    • Introduction
    • Files and locations
    • System, Global and Local extensions
    • Choosing an extension key
    • Naming conventions
    • Installing extensions
    • Declaration file
    • Configuration files
    • Configuration options
    • The Extension Manager (EM)
    • Creating a new extension
    • Creating a new distribution
    • Adding documentation
    • Other resources
  • TYPO3 API overview
    • Namespaces
    • Autoloading
    • Bootstrapping
    • Main classes and methods
      • High priority functions
      • Functions typically used and nice to know
    • Variables and Constants
      • Constants
      • Global variables
    • Backend User Object
    • TYPO3 Core Engine (TCE)
      • Database: TCEmain basics
      • Using TCEmain in scripts
      • The “tce_db.php” API
      • File functions basics
      • The “tce_file.php” API
    • Programming with workspaces in mind
    • Using the system log
    • Logging with TYPO3
      • Logger
      • Configuration of the Logging system
      • The LogRecord model
      • Log Writers
      • Log Processors
    • Using the system registry
    • Mail API
    • Form protection tool
    • Flash messages
    • TypoScript Syntax
      • What Is TypoScript?
      • Syntax
        • Introduction
        • Contexts
        • TypoScript syntax
        • Conditions
        • Includes
      • Sorting out Details
        • Parsing, Storing and Executing TypoScript
        • Myths, FAQ and Acknowledgements
      • The TypoScript Parser API
        • Introduction
        • Parsing Custom TypoScript
    • System categories
    • System collections
    • HTTP request library
    • Hooks
      • The concept of “hooks”
      • Hook configuration
      • Creating hooks
    • Extending classes (XCLASSes)
    • Various examples
      • Rendering page trees
      • Accessing the clipboard
      • Context-Sensitive Menus
      • Parsing HTML
      • Links to edit records
      • Support for custom tables in the Page module
      • Adding elements to the Content Element Wizard
      • Using custom permission options
  • Coding Guidelines
    • Introduction
    • File system conventions
      • TYPO3 directory structure
      • TYPO3 files and user files
      • Extension directory structure
      • File names
    • PHP file formatting
      • General requirements for PHP files
      • File structure
      • PHP syntax formatting
      • Using phpDoc
    • PHP architecture
      • Modeling Cross Cutting Concerns
        • Static methods, static classes, utility classes
        • Traits
        • Services
      • Working with exceptions
      • General links
    • Coding: Best practices
      • Accessing the database
      • Singletons
      • Static methods
      • Localization
      • Unit tests
      • Handling deprecation
      • Namespaces and class names of user files
  • JavaScript in TYPO3
    • AJAX in the TYPO3 Backend
      • In-depth presentation
      • Developing with AJAX in the TYPO3 Backend
    • Using ExtJS
      • Loading ExtJS
      • Ext.Direct
      • Backend Viewport
      • Page tree
      • Context-sensitive menus
  • Caching framework
    • Quick start for Integrators
    • Configuration
    • Caching framework architecture
    • Cache frontends
    • Cache backends
    • Developer information
  • Internationalization
    • Introduction to XLIFF
    • Migration to XLIFF and compatibility issues
    • Translating XLIFF files
  • Page types
  • User Settings Configuration
    • [‘ctrl’] section
    • [‘columns’] section
    • [‘showitem’] section
    • Extending the User Settings
    • Checking the configuration
  • Rich Text Editors (RTE)
    • Rich Text Editors in the TYPO3 backend
      • Plugging a RTE
      • API for Rich Text Editors
    • Transformations
      • Introduction
      • Process illustration
      • Transformation overview
      • Page TSconfig
      • Custom transformations API
  • Error and Exception Handling
    • Screenshots
    • Configuration
      • Error Handler
      • Production Exception Handler
      • Debug Exception Handler
      • Examples
      • Extending the error and exception handling
  • Data Formats
    • <T3DataStructure>
      • Elements
      • Sheet references
      • Syntax highlighting of a Data Structure
      • Parsing a Data Structure
    • <T3locallang>
      • Elements
  • Next Steps
  • Appendices
    • Appendix A: Historical perspective on RTE transformations
      • Properties and transformations
      • RTE transformations in Content Elements

PAGE CONTENTS

  • Links to edit records
    • Editing a record
    • Editing only a few fields from a record
    • Creating a form for new elements
  1. Start
  2. TYPO3 API overview
  3. Various examples
  4. Links to edit records
View source How to edit Edit on GitHub

Links to edit records¶

It is often needed to create links to edit records in the TYPO3 backend. The same syntax is also used for creating new records. TYPO3 provides an API for creating such links, namely \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(). This script will creates an onclick-JavaScript event linking to the alt_doc.php script in the PATH_typo3 directory.

This is not always needed, especially in backend modules using the dispatcher method (which should be all backend modules, since the dispatched was introduced in TYPO3 4.1). A simple link to alt_doc.php (with the proper parameters) works just as well.

Furthermore when using Fluid templates, you cannot call PHP code directly but have to wrap it in a view helper. The “examples” extensions demonstrates with the “edit link” view helper (\Documentation\Examples\ViewHelpers\Be\EditLinkViewHelper):

public function render($parameters, $returnUrl = '') {
        $uri = 'alt_doc.php?' . $parameters;
        if (!empty($returnUrl)) {
                $uri .= '&returnUrl=' . rawurlencode($returnUrl);
        }

        $this->tag->addAttribute('href', $uri);
        $this->tag->setContent($this->renderChildren());
        $this->tag->forceClosingTag(TRUE);
        return $this->tag->render();
}

This can then be used in the Fluid template. Below are a few examples, also demonstrating what kind of parameters must be passed to achieve various results:

<p>
        <Ex:be.editLink parameters="edit[pages][1]=edit" returnUrl="mod.php?M=tools_ExamplesExamples&tx_examples_tools_examplesexamples[action]=links" title="{f:translate(key: 'function_links_edit_page_1')}">
                <Ex:be.icon icon="actions-document-open" title="{f:translate(key: 'function_links_edit_page_1')}" />
                <f:translate key="function_links_edit_page_1" />
        </Ex:be.editLink>
</p>
<p>
        <Ex:be.editLink parameters="edit[pages][1]=edit&columnsOnly=title,hidden" returnUrl="mod.php?M=tools_ExamplesExamples&tx_examples_tools_examplesexamples[action]=links" title="{f:translate(key: 'function_links_edit_page_1_restricted')}">
                <Ex:be.icon icon="actions-document-open" title="{f:translate(key: 'function_links_edit_page_1_restricted')}" />
                <f:translate key="function_links_edit_page_1_restricted" />
        </Ex:be.editLink>
</p>
<p>
        <Ex:be.editLink parameters="&edit[tx_examples_haiku][1]=new&defVals[tx_examples_haiku][title]=New%20haiku" returnUrl="mod.php?M=tools_ExamplesExamples&tx_examples_tools_examplesexamples[action]=links" title="{f:translate(key: 'function_links_new_haiku')}">
                <Ex:be.icon icon="actions-document-new" title="{f:translate(key: 'function_links_new_haiku')}" />
                <f:translate key="function_links_new_haiku" />
        </Ex:be.editLink>
</p>

The links appear as one can expect:

Edit links in the examples BE module

The three different links in the “examples” BE module

Editing a record¶

The first example (edit[pages][1]=edit) opens the page with uid 1 for editing.

The general syntax is thus “&edit[tablename][uid]=edit”. You can specify as many tables and uids you like and you will get them all in one single form! The “uid” variable can even be a comma list of uids (short way of editing more records from the same table at once).

The examples above leads to the normal edit form for a page:

The standard form for editing a page

Page 1 ready for editing with the standard form

Editing only a few fields from a record¶

The second example does the same, but restricts the display to only the “title” and “hidden” fields (edit[pages][1]=edit&columnsOnly=title,hidden).

The fields can be listed in the “columnsOnly” parameter, as a comma-separated list. The example above results in the following:

The restricted form for editing a page

Page 1 ready for editing with a form showing only selected fields

Creating a form for new elements¶

The third example uses somewhat more complex parameters:

&edit[tx_examples_haiku][1]=new&defVals[tx_examples_haiku][title]=New%20haiku

The link triggers the creation a new record for the table “tx_examples_haiku” on page 1. It also sets a default value for the “title” field (“New haiku”). Note the following things:

  • the first parameter is still called “edit” even if this is about creating a new record. The creation of a record is indicated by the value “new”.
  • the value in the second pair of square brackets ([1]) indicates the page where the new record will be stored.
  • you need to URL-encode the values yourself, if needed (e.g. New%20haiku).

This results in the following form, standard but with a pre-filled title field.

Creating a new haiku

Form for creating a new haiku with pre-filled title

  • Previous
  • Next
  • Contact
  • Issues
  • Repository

Last updated: Apr 25, 2013 14:32

Last rendered: Jul 22, 2021 18:27

TYPO3 Theme 4.6.2

© Copyright Copyright since 2000 by the TYPO3 Documentation Team
  • Legal Notice
  • Privacy Policy