php

drushCommand_php_cli.sh
drush php:cli

drushCommand_php_eval.sh
drush php:eval

drushCommand_php_script.sh
drush php:script

14.04.2026 | Michael Ebert, Lothar Ferreira Neumann

drush php commands

You have a private files folder. The path could be set in settings.php like this:

settings.php
$settings['file_private_path'] = $app_root . '/../private_files/files';


Git status tells you the private files folder is untracked and you want to prevent data loss. This could be achieved by ignoring the folder in gitignore.

.gitignore
# Ignore private_files
/private_files/
Breadcrumb_builder_custom.php
  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    return $route_match->getRouteName() == 'commerce_cart.page';
  }

  /**
   * {@inheritdoc}
   */
  public function build(RouteMatchInterface $route_match) {
    // Node ID from shop
    $node = $this->entityTypeManager->getStorage('node')->load(3337);

    $breadcrumb = new Breadcrumb();
    $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
    $breadcrumb->addLink(Link::fromTextAndUrl($node->getTitle(), $node->toUrl()));

    return $breadcrumb;
  }
10.07.2025 | Lothar Ferreira Neumann, Mathias Grab

Manipulate breadcrumbs with custom logic

clear_cache.php
<?php

apcu_clear_cache();
opcache_reset();
13.11.2025 | Nikolas Kopp

Clear APC & Opcache

PipelineWebhookEventResource.php


$event = new PipelineEvent($data, $project);
$this->eventDispatcher->dispatch($event, 'webhook');
$this->eventDispatcher->dispatch($event, 'webhook.' . $event->type());
$this->eventDispatcher->dispatch($event, 'webhook.' . $event->type() . '.' . $event->status());
01.04.2025 | Marc Hitscherich, Dominik Wille

Dispatch multiple pipeline events based on more specific contexts

RouteSubscriber.php
<?php

namespace Drupal\scp_base\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Make sure profile pages are not admin pages, in order to load the right
    // translation.
    if ($route = $collection->get('profile.user_page.single')) {
      $route->setOption('_admin_route', FALSE);
    }
  }

}
RouteSubscriber.php
<?php

namespace Drupal\layout_builder_collapse_categories\Routing;

use Drupal\Core\Routing\RoutingEvents;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
use Drupal\layout_builder_collapse_categories\Controller\ChooseBlockController;

/**
 * Override the controller for layout_builder.move_block.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[RoutingEvents::ALTER] = ['onAlterRoutes', -1000];
    return $events;
  }

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    // Add a decorator for the choose_block conroller
    if ($route = $collection->get('layout_builder.choose_block')) {
      $defaults = $route->getDefaults();
      $route->setOption('original_controller', substr($defaults['_controller'], 0, strpos($defaults['_controller'], '::')));
      $defaults['_controller'] = ChooseBlockController::class . '::build';
      $route->setDefaults($defaults);
    }

  }
}
ChooseBlockController.php
<?php

namespace Drupal\layout_builder_collapse_categories\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\layout_builder\SectionStorageInterface;
use Drupal\Core\Controller\ControllerResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class ChooseBlockController extends ControllerBase {


  /**
   * The original ChooseBlockController
   *
   * @var \Drupal\layout_builder\Controller\ChooseBlockController $originalController
   */
  protected $originalController;

  /**
   * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
   */
  public function __construct(ControllerResolverInterface $controller_resolver, RouteMatchInterface $route_match) {
    $original_controller_class = $route_match->getRouteObject()->getOption('original_controller');
    $this->originalController = $controller_resolver->getControllerFromDefinition($original_controller_class);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('controller_resolver'),
      $container->get('current_route_match')
    );
  }

  public function build(SectionStorageInterface $section_storage, $delta, $region) {
    $build = $this->originalController->build($section_storage, $delta, $region);

    foreach ($build['block_categories'] as &$category) {
      if (isset($category['#open'])) {
        $category['#open'] = FALSE;
      }
      
    }

    return $build;
  }

}
16.07.2026 | Dominik Wille

Controller decorator

If you want to extend a class with static methods, don't use self:: since it will scope the static method to the extended class.

FooElement.php
// $options = self::getPluginOptions($element)
$options = static::getPluginOptions($element)
10.03.2023 | Fabian Alleblas, Dominik Wille

Replace self with static: Just do it, trust me.