headless icon indicating copy to clipboard operation
headless copied to clipboard

Hook into ContentObjectRenderer to extend getData

Open kitzberger opened this issue 3 years ago • 9 comments

Now you can access the frontendBase for the current base variant via TypoScript:

lib.frontendBase = TEXT
lib.frontendBase.data = site:frontendBase

kitzberger avatar May 25 '22 11:05 kitzberger

@lukaszuznanski, I'm confused about the whole URL generation. That's the reason for this approach here. In our project we wanna use absolute URLs for files. We've activated headless.frontendUrls and set frontendFileApi for all base variants.

For creating absolute URLs we've tried those two viewhelpers f:uri.typolink and f:uri.image. While they were working perfectly for our dev base variant, they've produced a completely different output on production (default base variant) ;-(

Example 1: {f:uri.typolink(parameter:path)}

Input: /fileadmin/my-document.pdf Output for dev base variant: http://www.my-project.org/fileadmin/my-document.pdf Output for default base variant: http://api.my-project.org/fileadmin/my-document.pdf

Example 2: {f:uri.image(src:path)}

Input: /fileadmin/my-document.pdf Output for dev base variant: http://www.my-project.org/fileadmin/my-document.pdf Output for default base variant: /fileadmin/my-document.pdf

Example 3: XmlSitemap

Links are only absolute if the non-default base-variant is being used!

kitzberger avatar May 25 '22 13:05 kitzberger

Hi @kitzberger, could you provide site yaml with variants file you are using? (with redacted domains)

twoldanski avatar Jun 01 '22 06:06 twoldanski

Hi @kitzberger, could you provide site yaml with variants file you are using? (with redacted domains)

@twoldanski, sure thing. It's usually something like this here:

base: 'https://api.example.org/'
frontendBase: 'https://www.example.org/'
frontendFileApi: 'https://www.example.org/fileadmin/'
baseVariants:
  -
    base: 'https://api.example.org:8080/'
    frontendBase: 'https://www.example.org:3000/'
    frontendFileApi: 'https://www.example.org:3000/fileadmin/'
    condition: 'like(applicationContext, "Development*") || applicationContext == "Production/Docker"'

But as a workaround we've now added another (redundant) baseVariant for "Production":

base: 'https://api.example.org/'
frontendBase: 'https://www.example.org/'
frontendFileApi: 'https://www.example.org/fileadmin/'
baseVariants:
  -
    base: 'https://api.example.org/'
    frontendBase: 'https://www.example.org/'
    frontendFileApi: 'https://www.example.org/fileadmin/'
    condition: 'applicationContext == "Production"'
  -
    base: 'https://api.example.org:8080/'
    frontendBase: 'https://www.example.org:3000/'
    frontendFileApi: 'https://www.example.org:3000/fileadmin/'
    condition: 'like(applicationContext, "Development*") || applicationContext == "Production/Docker"'

kitzberger avatar Jun 01 '22 06:06 kitzberger

@kitzberger thank you. I see where issue is. Right now we are resolving urls by each environment as variant as your "workaround". In your use-case you using base as production and variant only overrides for local development.

twoldanski avatar Jun 01 '22 06:06 twoldanski

@twoldanski, you're saying our workaround is the way it's supposed to be? At least for now?

kitzberger avatar Jun 01 '22 06:06 kitzberger

@kitzberger yes, current way -> you should define each env as variant, but you workflow is also valid, this patch should fix it for you https://github.com/TYPO3-Headless/headless/pull/435, I think this PR should be closed, I think this hook is not necessary either way.

twoldanski avatar Jun 02 '22 16:06 twoldanski

Still a valid new feature... I always like being able to read data via typoscript... And until now it's not possible to read those properties...

kitzberger avatar Jun 02 '22 16:06 kitzberger

Pull Request Test Coverage Report for Build 3337628169

  • 0 of 11 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.8%) to 62.996%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Classes/Hooks/ContentObjectRendererHook.php 0 11 0.0%
<!-- Total: 0 11
Totals Coverage Status
Change from base Build 3337589131: -0.8%
Covered Lines: 572
Relevant Lines: 908

💛 - Coveralls

coveralls avatar Oct 27 '22 13:10 coveralls

@kitzberger could please add test so we can merge this?

lukaszuznanski avatar Oct 27 '22 13:10 lukaszuznanski