Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically add robots.txt and favicon.ico per root page #717

Merged
merged 8 commits into from
Sep 3, 2019

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Sep 3, 2019

This PR provides two new routes:

  • /favicon.ico which provides the icon you can now select in the root page settings (the fallback one).
  • /robots.txt which provides the robots.txt for any root page (the fallback one). Users can manually enter content plus we have an event that allows us to extend it dynamically. The core uses it to dynamically add all sitemap.xml entries making it super convenient for users 🎉

@Toflar Toflar requested a review from leofeyer September 3, 2019 13:57
@@ -16,6 +16,13 @@ services:
tags:
- { name: kernel.event_listener, event: kernel.terminate, method: onKernelTerminate }

contao.listener.robots_txt:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have agreed on using the class name as service key for all new services, so this needs to become Contao\CoreBundle\EventListener\RobotsTxtListener.

@leofeyer leofeyer added this to the 4.9 milestone Sep 3, 2019
@Toflar Toflar changed the title Dynamically add robots.txt and favicon.ico per root page [RTM] Dynamically add robots.txt and favicon.ico per root page Sep 3, 2019
@leofeyer leofeyer self-requested a review September 3, 2019 21:41
@leofeyer leofeyer merged commit 21919f6 into master Sep 3, 2019
@leofeyer
Copy link
Member

leofeyer commented Sep 3, 2019

Thank you @Toflar.

@leofeyer leofeyer deleted the feature/robots-txt-favicon branch September 3, 2019 22:08
}

/**
* @Route("/favicon.ico", name="contao_favicon")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the route really need a route name? I mean noone will ever generate that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho a route should have a name yes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://symfony.com/doc/current/routing.html#generating-urls

If you don't set the route name explicitly with the name option, Symfony generates an automatic name based on the controller and action.

I think that would be totally fine in this case, noone ever will override the named route, as it is not used to generate a route anyway.

*
* @see RobotsTxtEvent
*/
public const ROBOTS_TXT = 'contao.robots_txt';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is deprecated in Symfony to use event names. The event class should be the name…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I cannot just change that atm as we do not require 4.4 yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not? Just use event::class as the event name?

- '@contao.framework'
- '@?fos_http_cache.http.symfony_response_tagger'
tags:
- controller.service_arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller.service_arguments tag is not needed if you don't get services in your action methods.

Copy link
Contributor

@fritzmg fritzmg Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik it is still needed for dependency injection in the constructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, what you mean is the service locator. But this controller does not extend from AbstractController so service locator is not used at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My custom controllers do not extend from AbstractController either and without the controller.service_arguments, no services would be injected into the constructor of the controller.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, or not, just checked it again. Setting the controller to public: true is enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, this PR is merged. If you want changes, create a new PR. Nothing will happen here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still following the discussion though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __invoke() method needs the Request object. Will this still work without the tag?

@leofeyer leofeyer changed the title [RTM] Dynamically add robots.txt and favicon.ico per root page Dynamically add robots.txt and favicon.ico per root page Dec 23, 2019
dmolineus added a commit to hofff/contao-trueurl that referenced this pull request Jan 24, 2020
Contao 4.9 introduces extra palette for root pages with fallback, see contao/contao#717
denniserdmann added a commit to denniserdmann/contao-opengraph3 that referenced this pull request Jul 13, 2021
As described [here] (contao/contao#717), since Contao 4.9 you need to add your fields to the new page type `rootfallback` in order to make them appear. 

Otherwise your fields will only appear, if the language fallback checkbox isn't selected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants