Giter Club home page Giter Club logo

linkhandler's Introduction

Linkhandler

This extensions uses the TYPO3 CMS Core API to provide the possibility to define additional tabs in the link browser to create links directly to specific records.

Originally the "linkhandler" was created by AOE GmbH. This fork progressively drifted away from the original and has now been nearly fully rewritten for TYPO3 CMS 7 LTS, using its new API.

Default configurations are provided for both "news" and "tt_news" extensions.

For a version compatible with TYPO3 CMS 6.2, please use the TYPO3_6-2 branch.

Configuration

The configuration comes in two parts. TSconfig is used to define the tabs for the link browser and TypoScript is used to define how to build the typolinks when rendering the links.

TSconfig

Default configurations can be included in any page using the new "Include Page TSConfig (from extensions):" feature when editing the "Resources" tab of a page.

This is the TSconfig used for linking to news records of extension "news":

// Page TSconfig for registering the linkhandler for "news" records
TCEMAIN.linkHandler.tx_news {
	handler = Cobweb\Linkhandler\RecordLinkHandler
	label = LLL:EXT:linkhandler/Resources/Private/Language/locallang.xlf:tab.news
	configuration {
		table = tx_news_domain_model_news
	}
	scanBefore = page
}

If you would like to link to any other type of record, just duplicate that configuration and change the label and configuration.table options.

You will also need to change the key used in the definition, i.e. tx_news in the above example. Make sure you use a unique key, otherwise your new configuration will override another one.

Leave the other options untouched.

Additional options exist and are described below:

configuration.storagePid

Forces the link browser to open directly in the page with the given id.

configuration.hidePageTree

Set to 1 to complete hide the page tree. This is particularly useful in conjunction with the storagePid option above, since it makes it possible to work with just a list of records without having to click around the page tree.

configuration.pageTreeMountPoints

Numbered array of page uid's which will be used instead of the full page tree.

The syntax is a numbered array:

pageTreeMountPoints {
	1 = 18
	2 = 91
}

TypoScript

Include TS static templates as needed.

Again let's consider the configuration for "news" as an example

plugin.tx_linkhandler.tx_news {

	// Do not force link generation when the news records are hidden or deleted.
	forceLink = 0

	typolink {
		parameter = {$plugin.tx_linkhandler.news.singlePid}
		additionalParams = &tx_news_pi1[news]={field:uid}&tx_news_pi1[controller]=News&tx_news_pi1[action]=detail
		additionalParams.insertData = 1
		useCacheHash = 1
	}
}

Note that the configuration key (i.e. tx_news) needs to be the same as the one used for the TSconfig part. The configuration is straight TS using the "typolink" function.

Special configuration options

forceLink

Set to 1 to force the link generation even if the record is hidden, deleted or the user is not allowed to access it.

typolink.mergeWithLinkhandlerConfiguration

This configuration is needed when creating a link directly with TypoScript and not in a content element. For example, with such a code:

lib.foo {
	10 = TEXT
	10 {
		typolink {
			mergeWithLinkhandlerConfiguration = 1
			parameter = record:tx_news:tx_news_domain_model_news:11 - foo "Link from TS menu"
			returnLast = url
		}
	}
}

In this case we want the returnLast = url parameter to be merged with the default rendering configuration. With the mergeWithLinkhandlerConfiguration = 1 we tell "linkhandler" to do just that.

Hooks

A single hook is provided. It can be used to manipulate most of the data from the \Cobweb\Linkhandler\TypolinkHandler class before the typolink is actually generated. An example usage could be to change the link target pid dynamically based on some values from the record being linked to.

Hook usage should be declared in an extension's ext_localconf.php file:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'][] = 'Foo\Bar\MyParameterProcessor';

The declared class must implement interface \Cobweb\Linkhandler\ProcessLinkParametersInterface. It can use the many getters and setters of \Cobweb\Linkhandler\TypolinkHandler to read and write data.

Soft reference handling

Extension "linkhandler" provides a soft reference parser which will pick any record being linked to and update the system references accordingly.

Linkvalidator support

This extension hooks into linkvalidator for checking record links. It is automatically activated. In case you want to disable it, you can use the following Page TSconfig:

To use it you have to adjust your linkvalidator TSConfig:

mod.linkvalidator.linktypes := removeFromList(tx_linkhandler)
}

There is an additional configuration option that allows the reporting of links that point to disabled records (hidden, start tieme not met yet, etc):

mod.linkvalidator {
	tx_linkhandler.reportHiddenRecords = 1
}

Migration

The extension provides a command-line tool to migrated old record references to new ones. Older versions of "linkhandler" used a 3-part syntax to point to a recored, i.e. record:table:uid. The current version uses a 4-part syntax (record:key:table:uid) which makes it possible to have several tabs/configurations for the same table.

To migrate old links, call the following:

/path/to/php typo3/cli_dispatch.phpsh extbase linkmigration:migrate

This will migrate links found in fields "tt_content.header_link", "tt_content.bodytext" and "sys_file_reference.link". To migrate data in other fields, use the "--fields" option:

/path/to/php typo3/cli_dispatch.phpsh extbase linkmigration:migrate --fields=tx_foo.bar,tx_foo.baz

For each table to which you had old links, the migration tool will ask you to enter a configuration key, which should correspond to the configuration keys you have declared in your TSconfig and TypoScripts configurations. This key will be added to the existing links to make them syntactically correct again.

Note that 4-part links are left untouched by this tool, so it is okay to run it several times on the same fields (should that happend for whatever reason).

As with all tools that modify your database, please make a backup before running it!

Tips & Tricks

Link browser width

You can use TSConfig to increase the with of the link browser windows in the backend. The default size is a bit too small especially when have those extra tabs.

RTE {
	default {
		buttons {
			link {
				dialogueWindow {
					width = 800
				}
			}
		}
	}
}

linkhandler's People

Contributors

astehlik avatar einarsvan avatar fnagel avatar fsuter avatar helhum avatar iamandrewluca avatar liayn avatar mocdk-dev avatar sorenmalling avatar waldhacker1 avatar webian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linkhandler's Issues

Upgrade to LTS 8 compatibility

Right now (correct me, if I am wrong) it is not possible to directly link to a tx_news element. Linkhandler would give that possibility I guess.

Thanks for your work

additionalWhereClause

In TsConfig an option additionalWhereClause to filter the records would be great.

Add the package in Packagist

As the repository is public and it's here on Github, it´s needed use a token access to download the package with Composer.

Add to Packagist fixes the problem, if this is considered a problem.

JS error in element browser (TYPO3 7.4)

When clicking a record in the element browser following fatal error occurs:

Uncaught ReferenceError: link_spec is not defined

It seems the link_spec function fired by a onclick handler on the record is not available.

Using TYPO3 7.4.0.

Linkhandler Menü disappears

I use
Typo3 7.6.18
Linkhandler 3.1.3

When I create a text element on a page and and use the headline link field (field header_link) it works wonderfully. If I create another text element after the first element and i use again the headline linke, the link handlers are displayed the linkhandler menu items, but when ein clicked on it, then the menu disappears. The header_link field works only, when it was the first Content-Element in the Page.

It is a bug or a problem with my installation?

This extension is missing on https://composer.typo3.org

The package "cobweb/linkhandler" is no longer available on TYPO3 composer repository.

I believe a couple of months ago I was able to install this extension without specifying current git repo inside the root composer.json(repositories array).
When did this change?

Typoscript parameter returnLast not considered

Hi!
I have a typoscript that set:
returnLast = url
(this parameter is not set in the EXT:linkhandler configuration but in a Typoscript lib that I use)

I guess that this is not considered because method 'main' in class TypolinkHandler doesn't parse $configuration variable where the returnLast parameter is present so what linkhandler returns is the full tag, not only the link.

Maybe it should merge $configuration with $typoScriptConfiguration before calling typolink.

P.S.: Thanks a lot for this fork!

Class 'Cobweb\Linkhandler\RecordLinkHandler' not found

After updating TYPO3 7.6.11 to 7.6.14 I get the error "Fatal error: Class 'Cobweb\Linkhandler\RecordLinkHandler' not found in ../typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 4535" when I try to set a link within the RTE. I have clear all caches and delete the typo3temp folder.

My configuration:

TCEMAIN.linkHandler.tx_news {
handler = Cobweb\Linkhandler\RecordLinkHandler
label = LLL:EXT:linkhandler/Resources/Private/Language/locallang.xlf:tab.news
configuration {
table = tx_news_domain_model_news
}
scanBefore = page
}

Get Hooks via ObjectManager

It would be nice to have Dependency Injection for the hook objects called in \Cobweb\Linkhandler\TypolinkHandler::generateLink

        // Call registered hooks
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'] as $className) {
                $linkParameterProcessor = GeneralUtility::makeInstance($className);
                if ($linkParameterProcessor instanceof ProcessLinkParametersInterface) {
                    $linkParameterProcessor->process($this);
                }
            }
        }

So maybe we could use the ObjectManager to get the hook objects?

I'd be glad to make a pull request.

Hook example

Can somebody give me an example how to use the hook?

Tree of linkbrowser in 6.2 not working anymore

There is a problem with the linkbrowser tree. It renders with a module token which gets refused by the core. To fix the problem the tx_linkhandler_recordsTree::PM_ATagWrap Method needs to be modified like below

    /**
     * Wrap the plus/minus icon in a link
     *
     * @param string $icon HTML string to wrap, probably an image tag.
     * @param string $cmd Command for 'PM' get var
     * @param boolean $bMark If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
     * @return string Link-wrapped input string
     * @todo Define visibility
     */
    public function PM_ATagWrap($icon, $cmd, $bMark = '') {
        $name = '';
        if ($bMark) {
            $anchor = '#' . $bMark;
            $name = ' name=' . $bMark;
        }
        $aOnClick = "return jumpToUrl(" .
            \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($this->getThisScript() . 'PM=' . $cmd . $this->_getaddPassOnParams()) .
            ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($anchor) . ');';

        return '<a href="#"' . htmlspecialchars($name) . ' onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>';
    }

Error on 6.2 class.tx_linkhandler_recordTab.php

Hi all,
when I choose folder with records I've got:
#1: PHP Warning: Creating default object from empty value in /home/users/aa/bb/typo3conf/ext/linkhandler/classes/class.tx_linkhandler_recordTab.php line 219
Can you help me please?

No records selectable when no access mount of the containing page

I have configured linkhandler with certain record types and pageTreeMountPoints / storagePid, but the records are only shown if I give the user the rights that the page is mounted in the regular page tree. This is bad because I have to mount them pages in the page tree where they normally have nothing to do (e.g. they should have the possiblity to link to news but not to create/edit news)…

additionalParams not properly read

Hello there,

I've stumbled accross a use case that isn't handled (at all) by linkhandler.

So what's happened to us is that a customer of ours wanted to link to a record and add a campaign parameter for the given link.

In order to do so, we added the following to the PageTS:

buttons.link.queryParametersSelector.enabled = 1

Now, this gives an additional field when browsing for links (for every possible link) that allows us to add any given additional parameter the customer wants.

BUT that case is not supported by the TypolinkHandler provided in 3.1.3, so we added it ourselves:

linkhandler/Classes/TypolinkHandler.php:132..134

        $additionalParams = explode('&', $linkParameterParts[2]);
        array_shift($additionalParams);
        $this->linkParameters['additionalParams'] .= '&' . implode('&', $additionalParams); 

Would it be possible for you to integrate this to the upcoming version?

Thanks for your feedback.

Tizian

three parts configuration && pageTreeMountPoints (TYPO3 7.x)

Two questions, see README.md

"If an old link is detected that consists only of three parts the first configuration found for the linked table will be used."

_"You can configure mount points for the page tree that is displayed in the element browser. ..." pageTreeMountPoints _

Has this been coded in the TYPO3 7.x Branch? Or only in the TYPO3 6.2 branch?

Regards,

Ra

Feature Request: Additional Option for Pid's

First things first. This really is a nice and easy to use Extension.
Just recently i discovered this Extension and now we are using it in our Company. We are using it to link tx_News and came across a Problem.
We have more than one News Detail Page. So it would be nice if you could select the Detail Page when you also select the News.
Is there a possibility to add a Option for adding a Page Id to the Link generated?

Class parameters from Linkwizard in generated link

Hi,
it seems like after adding a link in link wizard to a resource record the chosen classes in wizard are not included in generated link.
After adding the following lines to Classes/TypolinkHandler.php line 175 this worked for me:

// readd the class to link given in RTE back to link        
if($this->linkParameters['class']){
    $typoScriptConfiguration['ATagParams'] = 'class="'.$this->linkParameters['class'].'"';
}

Maybe you could include this in the next release?

no issue - but a request for a similar function: "record-picker" sponsoring possible

Sorry for missusing this repository - but maybe here there are some interested people around.

We need a functionality similar to linkhandler in the TYPO3 RTE. Our editors should be able to choose records from the database (like news or content elements or other records from our own extension). But not a link should be inserted in the "bodytext" but some special tag including the table and the uid. Today we use RTE user Elements for this to insert some special tag that is than evaluated by the parser. But this way the editor needs to know the uid of the record.

So the requirements (differences to linkhandler) are:

  • do not offer to make links to pages, files, folders... - but only to specified database records (can be defined in TSConfig)
  • do not insert a link in the "bodytext" like today
    <a href="record:tx_news:tx_news_domain_model_news:123">text</a>
    but somethig like:
    <record-picker>tx_news_domain_model_news,123</record-picker>
    or anything else that can pe parsed to insert some content within the rte text in the frontend using the content of the specified database record (eg. a news teaser).
  • some search possibility is needed (as linkhandler offers today)
  • would be great if this can be restricted to rte-blocks

As we don't have to much experience in the TYPO3 RTE we would need quite some time to develop while others may be able to get some faster solutions. We are willing to sponsor this with money. It can than be published in github or TER if you like.

CMS 7.5: Record/page browser in link wizard not working

Sorry to be the bearer of bad news, but as mentioned in #12 , in TYPO3 CMS 7.5 the page tree in the record browser ceased working. Clicking the little arrow on the left or right of a page will cause the entire BE to be loaded in the link wizard popover (only on linkhandler tabs)

Additionally, the JS error "Uncaught TypeError: Cannot read property 'Persistent' of undefined" gets logged.

Link is not saved after using the linkbrowser

When using the linkbrowser to choose a news record e.g., then a string like record:tx_news:tx_news_domain_model_news:267 is put into the link field but it is not saved when saving the record. I guess only the value in the visible input field is changed but not in the invisible field, TYPO3 uses regularly.

Any plan for TYPO3 8.6?

Hi,
thanks for this nice ext.
Is there a plan for the new TYPO3 LTS 8 version?
Thank you...

Git versioning / tagging

Hey

Would be possible to create git tag for stable version of linkhandler. To be able to use as composer version ...
Now I'm using "cobweb/linkhandler": "dev-master" and by the development process some bugs can get to my site.

Thanks

Render correct link when insert a link in extension rte

Hi,
thanks for this fork.
I try using linkhandler in TYPO3 7LTS with my own extension. All will work, if I insert an links to records of my extension in standard content elements.

But when I link to a record of my extension in the RTE from another record of my extension the link will not rendered correctly in the frontend. It looks like "record:tx_myext:tx_myext_domain_model_data:10"

My Page TS:
TCEMAIN.linkHandler.tx_myext {
handler = Cobweb\Linkhandler\RecordLinkHandler
label = Produkte
configuration {
table = tx_myext_domain_model_data
}
scanBefore = page
}

My TS

plugin.tx_linkhandler {
tx_myext {
listTables = tx_myext_domain_model_data
typolink {
parameter = {field:pid}
parameter.insertData = 1
additionalParams = &tx_myext_data[data]={field:uid}
additionalParams.insertData = 1
useCacheHash = 1
}
}
}

Is this a bug or is smething wrong with my configuration?

Thanks
Stephan

RTE is fine - other fields fail

If I link a record in RTE link is created as should.

If I create a link inside a field (header link, new related links, etc) and render it in the view with these settings:
<f:link.typolink parameter="{link.uri}" target="{newsItem.uid}" title="{link.title}" >{link.title}</f:link.typolink>

It produces no link, but just the text.

Do I need to configure anything to get TypoLink Viewhelper working with your extension?

returnLast=target not supported

Hi,
I try to use in the ext:news a news of the type 'internal link' and choose a linkhandler-link as link.

In the frontend the link looks ok, but the target-tag also contains the full url. The news-extension get the target with the following code:

protected function getTargetConfiguration(array $configuration)
{
$configuration['returnLast'] = 'target';
return $this->cObj->typoLink('dummy', $configuration);
}

This function will return the full url, not the target. Is there a possibility to change this behaviour?

Fields lost in link generation

Hi @cobwebch,
I use this in Fluid

<f:cObject typoscriptObjectPath="lib.link"
           data="{
                text: ' ',
                link: '{tile.link}',
                class: 'expandAndCenter tile-link tile-image lazyload {tileImageClass}',
                style: 'background-image: url(\'/{imgPlaceholderUri}\')',
                data-src: '{imgUri}'
                }" />

and this is the lib.link Typoscript

lib.link = COA
lib.link {
    10 = TEXT
    10 {
        field = text
        typolink {
            mergeWithLinkhandlerConfiguration = 1
            parameter = {field:link}
            parameter.insertData = 1
            ATagParams = class="{field:class}" style="{field:style}" data-src="{field:data-src}"
            ATagParams.insertData = 1
        }
    }
}

The problem is that all the fields, like {field:class}, are lost in the generation of the url by linkhandler that returns only url.

I'm still trying to make a patch but actually I'm stuck.

Display only default language in link browser

Hi @cobwebch,
first of all I'm sorry for the long post, this is a small problem but a little hard to analyze.

Actually in the link browser there are displayed both the default language records and the translated records.
I found out that, at least in my installations, if an editor picks a translated record then the generated link causes problems with the fragile Realurl 2.
Instead if the editor picks the default language records there are no problem and even the translated pages display the links to the right translated records.

By instance, these are the links that appear in EXT:news list for default and second language:
Default language:
index.php?id=44&L=0&tx_news_pi1%5Bnews%5D=100181&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Baction%5D=detail&cHash=6c102a4644eba9390869bb79afd60104
Second language:
index.php?id=44&L=1&tx_news_pi1%5Bnews%5D=100181&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Baction%5D=detail&cHash=6c102a4644eba9390869bb79afd60104

Everything is ok and the only thing that changes is the L parameter.

Now, if we use instead the link browser and we pick the second language record the link becomes:
index.php?id=44&L=1&tx_news_pi1%5Bnews%5D=100182&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Baction%5D=detail&cHash=68d9bb161c64e5bc17baf08180d21202

Here what changed are the parameters: L; news uid; cHash.
For Realurl 2 obviously it is a different url even if it display the correct content.

The real problem is that at the end we have 2 different urls with the same content, bad for SEO.

I tried to find a way to display only the default language record in the link browser but I'm unable to find a viable solution.

The problem could be easily solved if there was a way to set to false $this->localizationView of DatabaseRecordList so only the default language records would be displayed in the link browser but I can't find a way to set it without hacking the core.

One ugly solution could be to temporary store $GLOBALS['TCA'][$table]['ctrl']['languageField'] and then unset it before calling DatabaseRecordList->getTable(). But this need also to use getTable hook to change the where clause.

Please, do you have any other idea?

Search function not working

On typo3 6.1, the search function for records does'nt seem to work anymore : no result is returned no matter the search string.

Bug when using linkhandler with link field in extension

Thanks for the linkhandler fork with support for TYPO3 CMS 6.0 or in my case TYPO3 6.1.

Perhaps you can attach the following patch into your fork.
http://forge.typo3.org/issues/26780

I have spent hours to find and get the solution for a problem with links to tx_news or tx_cal in the header_link field an the plaintext rendering of direct_mail :-(
The patch could save other people time and trouble :-)

composer configuration broken

Can't use composer, because I get conflict with invalid version string:

Error message:
Skipped branch master, Could not parse version constraint self-version: Invalid version string "self-version"

No selection of link possible

Hi, using the latest linkbrowser (3.1.3) the link browser dialog does not close after selecting a record.

Example config:

TCEMAIN.linkHandler.citko_directory_verein {
handler = Cobweb\Linkhandler\RecordLinkHandler
label = Verein
configuration {
table = tx_citkodirectory_domain_model_eintrag
storagePid = 328
hidePageTree = 0
}
scanBefore = page
}

Tested with Chrome, Firefox TYPO3 7.6.11 and 7.6.12. I see no error in the browser console, the dialog simply does not close.

Additional info: 3.1.2 works as expected.

question because of different detail pages

hi,

the extension works fine in typo3 v7.

is there a possibility link to different detailpages according to the storage pids?

or can i only habe one detail link.

plugin.tx_linkhandler.tx_news.typolink.parameter = 42

Class 'Cobweb\Linkhandler\RecordLinkHandler' not found

I receive this messege when trying to set a link within RTE under Typo3 7.6.10. Extension is installed, shown under "Installed Extensions" and I have added a configuration for page ts. Probably I am missing something and it is no bug.

My configuration:
TCEMAIN.linkHandler.tx_xxxxx_project {
handler=Cobweb\Linkhandler\RecordLinkHandler
label=MyProjects
configuration {
table = tx_xxxxx_project
storagePid = 64
}
displayAfter = page
scanAfter = page
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.