nerdfisch: DevBits

Kleine, aber feine Code-Snippets, nützliche Tweaks und elegante Lösungsansätze aus dem Entwickler-Alltag

13.11.2025 | Marc Hitscherich

List MySQL tables by size

table-size.sql
SELECT table_name AS `table`, round(((data_length + index_length) / 1024 / 1024), 2) `size in MB`
FROM information_schema.TABLES
WHERE table_schema = "DATABASE_NAME"
ORDER BY `size in MB` DESC
LIMIT 10;
sql
mysql
operations
database
databases
copy-paste
13.11.2025 | Mathias Grab

How to add a Drupal error message and log entry

error_handling.php
<?php

$error_message = t('There is an error with this.');

\Drupal::messenger()->addError($error_message));
\Drupal::logger('my_module')->log('error', $error_message);
php
error handling
13.11.2025 | Mathias Grab

Remove the "- None -" option from select fields

Without required field

Select field without requirement

With required field

Select field with requirement
site building
manipulating forms
13.11.2025 | Mathias Grab

How to create local task links

my_module.links.task.yml
my_module.my_local_task_link:
  route_name: my_module.custom_route
  title: "Title"
  base_route: route_where.local_task.should_be_placed
yml / yaml
local task links
routing
13.11.2025 | Nikolas Kopp

Clear APC & Opcache

clear_cache.php
<?php

apcu_clear_cache();
opcache_reset();
php
drush
Drush
caching
cache
Debugging
debugging
debug