(TYPO3, TypoScript)

lib.parseFunc_RTE A-Tag automatisch erweitern

RTE / CK Editor Links erweitern

Ein hoffentlich sinnvolles Snippet...

Hiermit kann man an RTE / CK Editor Download Tags Informationen zum Download automatisch an das Link Tag  (title="...", downlaod="...") und den Link Text (Dateiendung, Dateigröße) anhängen.

So sieht dann ein Download Link (hip, 130KB) aus, File Extension und Size am Text, sowie Title und Download Attribute am A-Tag.
Im Backend wurde nur die Datei verlinkt, also dort "De(r)faul(t)e Redakteur" Eingabe, nix "Sie müssen erst den Nippel durch die Lasche ziehn" ;-)

<a class="link_internal_download" href="t3://file?uid=113">Download Link</a>

Hier das Typoscript Snippet, sollte so auch mehrsprachig funktionieren.

// COA in examples below
// Yes, I know not needed in postCObject .. could be mapped directly to FILES
lib.parseFunc_RTE {
    // add file extension and file size to link Text
    tags.a {
        // data in the box :-)
        // parameters:href  <-- we'll need this one
        // parameters:target
        // parameters:class
        // parameters:title
        postCObject = COA
        postCObject {
            10 = FILES
            10 {
                if {
                    equals = t3://file
                    value {
                        data = parameters:href
                        stdWrap.substring = 0,9
                    }
                }
                files {
                    // variant 1 to grab file uid
                    data = parameters:href
                    // replace string before uid
                    replacement {
                        10 {
                            search = t3://file?uid=
                            replace =
                        }
                    }
                }
                renderObj = COA
                renderObj {
                    10 = TEXT
                    10 {
                        noTrimWrap = | ({file:current:extension}, |)|
                        insertData = 1
                        data = file:current:size
                        bytes = 1
                        bytes.labels = "B|KB|MB|GB"
                    }
                }
            }
        }
        // add default title and e.g: download attribute
        typolink.ATagParams.stdWrap.outerWrap.cObject = COA
        typolink.ATagParams.stdWrap.outerWrap.cObject {
            10 = FILES
            10 {
                stdWrap.if {
                    equals = t3://file
                    value {
                        data = parameters:href
                        stdWrap.substring = 0,9
                    }
                }
                files {
                    // variant 2 to grab file uid
                    data = parameters:href
                    // split by = (equals sign aka char 61) and return second value
                    split {
                        token.char = 61
                        returnKey = 1
                    }
                }
                renderObj = COA
                renderObj {
                    // add title, if not set
                    10 = TEXT
                    10 {
                        noTrimWrap = | title="Download: |" |
                        // download_name and as fallback name
                        data = file:current:download_name // file:current:name
                        stdWrap.dataWrap = |.{file:current:extension}
                        stdWrap.dataWrap.if.isTrue.data = file:current:download_name
                    }
                    // add download name or other attributes
                    20 = TEXT
                    20 {
                        noTrimWrap = | download="|" |
                        data = file:current:download_name // file:current:name
                        stdWrap.dataWrap = |.{file:current:extension}
                        stdWrap.dataWrap.if.isTrue.data = file:current:download_name
                    }
                }
            }
        }
    }
}