Drupal8

How do I use PHP in Drupal 8?

Drupal Loves PHP, but it loves MVC and OOP now too!

I have to admit, I'm partially writing this post just to see in my analytics reporting how many people are searching for it. But for those that are trying to wedge PHP into Drupal8 and having trouble with it, there is something here for you.

The PHP Filter has been moved out of core and is now a contib module. It was also not working during the release-candidate phase of Drupal 8, but seems to be back on track now. Sometimes people like to do crazy things like create a Panels page at a certain URL and then enable the PHP text filter. If you're slick you might do an include() or an include_once() command and call your scripts from a directory where they can be managed in a code repository and such.

But it's a drag creating a huge Panels page, with all its features, just to call an include() command. And you have to create a Panel for each path (or route) you want to bring into existence. This is pretty heavy for just having a route to call a script.

Tags: 

Getting Drupal8 Config and Variable Info with Twig and/or PHP

Drupal8, Symphony2, Twig and PHP - so happy together?

OK, so here we are. Drupal 8 and Twig. No longer can you do things like drupal_get_title() and instead you have to pull variables through a more stringent Model-View-Controller arrangement, specifically Drupal8/Symfony2 and the Twig templating engine. And many Drupal7 commands are gone, so you have to use the object-oriented approach to get information directly in PHP. So here is a progressively-building cheat-sheet of how to pull certain configs and variables using PHP and/or Twig variables specific to Drupal 8:


Get the Drupal8 Site Name and Slogan in PHP

Tags: 

Subscribe to RSS - Drupal8