Uncategorized

Let’s debug in Drupal 8 !

It has been nearly 7 months since Drupal 8 first release and as a developer, I am still in the learning process. It can be hard sometimes to know what is going wrong with your code and how to solve it. I will tell you about few things to know on how to develop and debug Drupal 8 projects and continue learning, learning and learning !

Disabling cache

First of all, to avoid having a crazy terminal with thousands of drupal cr hits, you can disable Drupal caching during development. You need to copy and rename sites/example.settings.local.php file to sites/default/settings.local.php. Then uncomment/update some values:

  • uncomment this line to enable the “null cache service”:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
  • uncomment these lines to disable CSS/JS aggregation:
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
  • uncomment these lines to disable the render cache and the dynamic page cache:
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  • you can allow test modules and themes to be installed if needed with:
$settings['extension_discovery_scan_tests'] = TRUE;

To include this file as part of Drupal’s settings file, open sites/default/settings.php file and uncomment these lines:

if (file_exists(__DIR__ . '/settings.local.php')) {
    include __DIR__ . '/settings.local.php';
}

Then, to disable Twig caching, open sites/development.services.yml file and add the following settings:

parameters:
    twig.config:
        debug: true
        auto_reload: true
        cache: false

Finally, rebuild the Drupal cache and it is done !

Displaying errors

As in Drupal 7, you can set different levels of errors display (by visiting this page: /admin/config/development/logging in the administration interface):

  • None
  • Errors and warnings
  • All

In Drupal 8, there is a fourth level called “All messages, with backtrace information”. This is native to Drupal core and it allows to display the error backtrace in the message area.

You can also adjust the level of errors in your local setting file:

$config['system.logging']['error_level'] = 'verbose';

Creating log messages

Developers from Drupal 7 know the Database Logging module that allows to log messages in the database using the famous watchdog() function.

Well, this module still exists in Drupal 8 but the function has a replacement : the Drupal 8 logger class.

It looks like this:

// Logs an error
\Drupal::logger('my_module')->error($message);

Let’s have a look at the different parts of the code:

  • \Drupal::logger(‘my_module') is the helper method that quickly creates a copy of the logger service. As a parameter, it takes the module name from where we log the information;
  • ->error:this is the severity-level method (it can be debuginfonoticewarningerrorcriticalalertemergency);
  • $message is the log message. It can be a simple string or it can contain some placeholders. In this case, you can pass the associative array (placeholders as keys) as a second parameter.

All the messages created with the logger service can be viewed in the reports page of the administration interface in /admin/reports/dblog as it used to be in Drupal 7.

Debugging Twig templates

Drupal core comes with a theming debug mode that is really helpful for local environments. To enable it, copy-and-paste the following code into sites/default/services.yml file (if you haven’t already added these lines in development.services.yml):

parameters:
    twig.config:
        debug: true

Thanks to this mode, it will be easier to find out which portion of HTML code has been written in which templates: in the source code, you will see each part of Twig templates (pages, nodes, blocks, menus etc.) surrounded by HTML comments that contain the matching suggestion templates. The one in current use will be checked.

 

 

Bitcoin Blogs 3001
Bitcoin Blogs 3002
Bitcoin Blogs 3003
Bitcoin Blogs 3004
Bitcoin Blogs 3005
Bitcoin Blogs 3006
Bitcoin Blogs 3007
Bitcoin Blogs 3008
Bitcoin Blogs 3009
Bitcoin Blogs 3010
Bitcoin Blogs 3011
Bitcoin Blogs 3012
Bitcoin Blogs 3013
Bitcoin Blogs 3014
Bitcoin Blogs 3015
Bitcoin Blogs 3016
Bitcoin Blogs 3017
Bitcoin Blogs 3018
Bitcoin Blogs 3019
Bitcoin Blogs 3020
Bitcoin Blogs 3021
Bitcoin Blogs 3022
Bitcoin Blogs 3023
Bitcoin Blogs 3024
Bitcoin Blogs 3025
Bitcoin Blogs 3026
Bitcoin Blogs 3027
Bitcoin Blogs 3028
Bitcoin Blogs 3029
Bitcoin Blogs 3030
Bitcoin Blogs 3031
Bitcoin Blogs 3032
Bitcoin Blogs 3033
Bitcoin Blogs 3034
Bitcoin Blogs 3035
Bitcoin Blogs 3036
Bitcoin Blogs 3037
Bitcoin Blogs 3038
Bitcoin Blogs 3039
Bitcoin Blogs 3040
Bitcoin Blogs 3041
Bitcoin Blogs 3042
Bitcoin Blogs 3043
Bitcoin Blogs 3044
Bitcoin Blogs 3045
Bitcoin Blogs 3046
Bitcoin Blogs 3047
Bitcoin Blogs 3048
Bitcoin Blogs 3049
Bitcoin Blogs 3050
Bitcoin Blogs 3051
Bitcoin Blogs 3052
Bitcoin Blogs 3053
Bitcoin Blogs 3054
Bitcoin Blogs 3055
Bitcoin Blogs 3056
Bitcoin Blogs 3057
Bitcoin Blogs 3058
Bitcoin Blogs 3059
Bitcoin Blogs 3060
Bitcoin Blogs 3061
Bitcoin Blogs 3062
Bitcoin Blogs 3063
Bitcoin Blogs 3064
Bitcoin Blogs 3065
Bitcoin Blogs 3066
Bitcoin Blogs 3067
Bitcoin Blogs 3068
Bitcoin Blogs 3069
Bitcoin Blogs 3070
Bitcoin Blogs 3071
Bitcoin Blogs 3072
Bitcoin Blogs 3073
Bitcoin Blogs 3074
Bitcoin Blogs 3075
Bitcoin Blogs 3076
Bitcoin Blogs 3077
Bitcoin Blogs 3078
Bitcoin Blogs 3079
Bitcoin Blogs 3080
Bitcoin Blogs 3081
Bitcoin Blogs 3082
Bitcoin Blogs 3083
Bitcoin Blogs 3084
Bitcoin Blogs 3085
Bitcoin Blogs 3086
Bitcoin Blogs 3087
Bitcoin Blogs 3088
Bitcoin Blogs 3089
Bitcoin Blogs 3090
Bitcoin Blogs 3091
Bitcoin Blogs 3092
Bitcoin Blogs 3093
Bitcoin Blogs 3094
Bitcoin Blogs 3095
Bitcoin Blogs 3096
Bitcoin Blogs 3097
Bitcoin Blogs 3098
Bitcoin Blogs 3099
Bitcoin Blogs 3100
Bitcoin Blogs 3101
Bitcoin Blogs 3102
Bitcoin Blogs 3103
Bitcoin Blogs 3104
Bitcoin Blogs 3105
Bitcoin Blogs 3106
Bitcoin Blogs 3107
Bitcoin Blogs 3108
Bitcoin Blogs 3109
Bitcoin Blogs 3110
Bitcoin Blogs 3111
Bitcoin Blogs 3112
Bitcoin Blogs 3113
Bitcoin Blogs 3114
Bitcoin Blogs 3115
Bitcoin Blogs 3116
Bitcoin Blogs 3117
Bitcoin Blogs 3118
Bitcoin Blogs 3119
Bitcoin Blogs 3120
Bitcoin Blogs 3121
Bitcoin Blogs 3122
Bitcoin Blogs 3123
Bitcoin Blogs 3124
Bitcoin Blogs 3125
Bitcoin Blogs 3126
Bitcoin Blogs 3127
Bitcoin Blogs 3128
Bitcoin Blogs 3129
Bitcoin Blogs 3130
Bitcoin Blogs 3131
Bitcoin Blogs 3132
Bitcoin Blogs 3133
Bitcoin Blogs 3134
Bitcoin Blogs 3135
Bitcoin Blogs 3136
Bitcoin Blogs 3137
Bitcoin Blogs 3138
Bitcoin Blogs 3139
Bitcoin Blogs 3140
Bitcoin Blogs 3141
Bitcoin Blogs 3142
Bitcoin Blogs 3143
Bitcoin Blogs 3144
Bitcoin Blogs 3145
Bitcoin Blogs 3146
Bitcoin Blogs 3147
Bitcoin Blogs 3148
Bitcoin Blogs 3149
Bitcoin Blogs 3150
Bitcoin Blogs 3151
Bitcoin Blogs 3152
Bitcoin Blogs 3153
Bitcoin Blogs 3154
Bitcoin Blogs 3155
Bitcoin Blogs 3156
Bitcoin Blogs 3157
Bitcoin Blogs 3158
Bitcoin Blogs 3159
Bitcoin Blogs 3160
Bitcoin Blogs 3161
Bitcoin Blogs 3162
Bitcoin Blogs 3163
Bitcoin Blogs 3164
Bitcoin Blogs 3165
Bitcoin Blogs 3166
Bitcoin Blogs 3167
Bitcoin Blogs 3168
Bitcoin Blogs 3169
Bitcoin Blogs 3170
Bitcoin Blogs 3171
Bitcoin Blogs 3172
Bitcoin Blogs 3173
Bitcoin Blogs 3174
Bitcoin Blogs 3175
Bitcoin Blogs 3176
Bitcoin Blogs 3177
Bitcoin Blogs 3178
Bitcoin Blogs 3179
Bitcoin Blogs 3180
Bitcoin Blogs 3181
Bitcoin Blogs 3182
Bitcoin Blogs 3183
Bitcoin Blogs 3184
Bitcoin Blogs 3185
Bitcoin Blogs 3186
Bitcoin Blogs 3187
Bitcoin Blogs 3188
Bitcoin Blogs 3189
Bitcoin Blogs 3190
Bitcoin Blogs 3191
Bitcoin Blogs 3192
Bitcoin Blogs 3193
Bitcoin Blogs 3194
Bitcoin Blogs 3195
Bitcoin Blogs 3196
Bitcoin Blogs 3197
Bitcoin Blogs 3198
Bitcoin Blogs 3199
Bitcoin Blogs 3200
Bitcoin Blogs 3201
Bitcoin Blogs 3202
Bitcoin Blogs 3203
Bitcoin Blogs 3204
Bitcoin Blogs 3205
Bitcoin Blogs 3206
Bitcoin Blogs 3207
Bitcoin Blogs 3208
Bitcoin Blogs 3209
Bitcoin Blogs 3210
Bitcoin Blogs 3211
Bitcoin Blogs 3212
Bitcoin Blogs 3213
Bitcoin Blogs 3214
Bitcoin Blogs 3215
Bitcoin Blogs 3216
Bitcoin Blogs 3217
Bitcoin Blogs 3218
Bitcoin Blogs 3219
Bitcoin Blogs 3220
Bitcoin Blogs 3221
Bitcoin Blogs 3222
Bitcoin Blogs 3223
Bitcoin Blogs 3224
Bitcoin Blogs 3225
Bitcoin Blogs 3226
Bitcoin Blogs 3227
Bitcoin Blogs 3228
Bitcoin Blogs 3229
Bitcoin Blogs 3230
Bitcoin Blogs 3231
Bitcoin Blogs 3232
Bitcoin Blogs 3233
Bitcoin Blogs 3234
Bitcoin Blogs 3235
Bitcoin Blogs 3236
Bitcoin Blogs 3237
Bitcoin Blogs 3238
Bitcoin Blogs 3239
Bitcoin Blogs 3240
Bitcoin Blogs 3241
Bitcoin Blogs 3242
Bitcoin Blogs 3243
Bitcoin Blogs 3244
Bitcoin Blogs 3245
Bitcoin Blogs 3246
Bitcoin Blogs 3247
Bitcoin Blogs 3248
Bitcoin Blogs 3249
Bitcoin Blogs 3250
Bitcoin Blogs 3251
Bitcoin Blogs 3252
Bitcoin Blogs 3253
Bitcoin Blogs 3254
Bitcoin Blogs 3255
Bitcoin Blogs 3256
Bitcoin Blogs 3257
Bitcoin Blogs 3258
Bitcoin Blogs 3259
Bitcoin Blogs 3260
Bitcoin Blogs 3261
Bitcoin Blogs 3262
Bitcoin Blogs 3263
Bitcoin Blogs 3264
Bitcoin Blogs 3265
Bitcoin Blogs 3266
Bitcoin Blogs 3267
Bitcoin Blogs 3268
Bitcoin Blogs 3269
Bitcoin Blogs 3270
Bitcoin Blogs 3271
Bitcoin Blogs 3272
Bitcoin Blogs 3273
Bitcoin Blogs 3274
Bitcoin Blogs 3275
Bitcoin Blogs 3276
Bitcoin Blogs 3277
Bitcoin Blogs 3278
Bitcoin Blogs 3279
Bitcoin Blogs 3280
Bitcoin Blogs 3281
Bitcoin Blogs 3282
Bitcoin Blogs 3283
Bitcoin Blogs 3284
Bitcoin Blogs 3285
Bitcoin Blogs 3286
Bitcoin Blogs 3287
Bitcoin Blogs 3288
Bitcoin Blogs 3289
Bitcoin Blogs 3290
Bitcoin Blogs 3291
Bitcoin Blogs 3292
Bitcoin Blogs 3293
Bitcoin Blogs 3294
Bitcoin Blogs 3295
Bitcoin Blogs 3296
Bitcoin Blogs 3297
Bitcoin Blogs 3298
Bitcoin Blogs 3299
Bitcoin Blogs 3300
Bitcoin Blogs 3301
Bitcoin Blogs 3302
Bitcoin Blogs 3303
Bitcoin Blogs 3304
Bitcoin Blogs 3305
Bitcoin Blogs 3306
Bitcoin Blogs 3307
Bitcoin Blogs 3308
Bitcoin Blogs 3309
Bitcoin Blogs 3310
Bitcoin Blogs 3311
Bitcoin Blogs 3312
Bitcoin Blogs 3313
Bitcoin Blogs 3314
Bitcoin Blogs 3315
Bitcoin Blogs 3316
Bitcoin Blogs 3317
Bitcoin Blogs 3318
Bitcoin Blogs 3319
Bitcoin Blogs 3320
Bitcoin Blogs 3321
Bitcoin Blogs 3322
Bitcoin Blogs 3323
Bitcoin Blogs 3324
Bitcoin Blogs 3325
Bitcoin Blogs 3326
Bitcoin Blogs 3327
Bitcoin Blogs 3328
Bitcoin Blogs 3329
Bitcoin Blogs 3330
Bitcoin Blogs 3331
Bitcoin Blogs 3332
Bitcoin Blogs 3333
Bitcoin Blogs 3334
Bitcoin Blogs 3335
Bitcoin Blogs 3336
Bitcoin Blogs 3337
Bitcoin Blogs 3338
Bitcoin Blogs 3339
Bitcoin Blogs 3340
Bitcoin Blogs 3341
Bitcoin Blogs 3342
Bitcoin Blogs 3343
Bitcoin Blogs 3344
Bitcoin Blogs 3345
Bitcoin Blogs 3346
Bitcoin Blogs 3347
Bitcoin Blogs 3348
Bitcoin Blogs 3349
Bitcoin Blogs 3350
Bitcoin Blogs 3351
Bitcoin Blogs 3352
Bitcoin Blogs 3353
Bitcoin Blogs 3354
Bitcoin Blogs 3355
Bitcoin Blogs 3356
Bitcoin Blogs 3357
Bitcoin Blogs 3358
Bitcoin Blogs 3359
Bitcoin Blogs 3360
Bitcoin Blogs 3361
Bitcoin Blogs 3362
Bitcoin Blogs 3363
Bitcoin Blogs 3364
Bitcoin Blogs 3365
Bitcoin Blogs 3366
Bitcoin Blogs 3367
Bitcoin Blogs 3368
Bitcoin Blogs 3369
Bitcoin Blogs 3370
Bitcoin Blogs 3371
Bitcoin Blogs 3372
Bitcoin Blogs 3373
Bitcoin Blogs 3374
Bitcoin Blogs 3375
Bitcoin Blogs 3376
Bitcoin Blogs 3377
Bitcoin Blogs 3378
Bitcoin Blogs 3379
Bitcoin Blogs 3380
Bitcoin Blogs 3381
Bitcoin Blogs 3382
Bitcoin Blogs 3383
Bitcoin Blogs 3384
Bitcoin Blogs 3385
Bitcoin Blogs 3386
Bitcoin Blogs 3387
Bitcoin Blogs 3388
Bitcoin Blogs 3389
Bitcoin Blogs 3390
Bitcoin Blogs 3391
Bitcoin Blogs 3392
Bitcoin Blogs 3393
Bitcoin Blogs 3394
Bitcoin Blogs 3395
Bitcoin Blogs 3396
Bitcoin Blogs 3397
Bitcoin Blogs 3398
Bitcoin Blogs 3399
Bitcoin Blogs 3400
Bitcoin Blogs 3401
Bitcoin Blogs 3402
Bitcoin Blogs 3403
Bitcoin Blogs 3404
Bitcoin Blogs 3405
Bitcoin Blogs 3406
Bitcoin Blogs 3407
Bitcoin Blogs 3408
Bitcoin Blogs 3409
Bitcoin Blogs 3410
Bitcoin Blogs 3411
Bitcoin Blogs 3412
Bitcoin Blogs 3413
Bitcoin Blogs 3414
Bitcoin Blogs 3415
Bitcoin Blogs 3416
Bitcoin Blogs 3417
Bitcoin Blogs 3418
Bitcoin Blogs 3419
Bitcoin Blogs 3420
Bitcoin Blogs 3421
Bitcoin Blogs 3422
Bitcoin Blogs 3423
Bitcoin Blogs 3424
Bitcoin Blogs 3425
Bitcoin Blogs 3426
Bitcoin Blogs 3427
Bitcoin Blogs 3428
Bitcoin Blogs 3429
Bitcoin Blogs 3430
Bitcoin Blogs 3431
Bitcoin Blogs 3432
Bitcoin Blogs 3433
Bitcoin Blogs 3434
Bitcoin Blogs 3435
Bitcoin Blogs 3436
Bitcoin Blogs 3437
Bitcoin Blogs 3438
Bitcoin Blogs 3439
Bitcoin Blogs 3440
Bitcoin Blogs 3441
Bitcoin Blogs 3442
Bitcoin Blogs 3443
Bitcoin Blogs 3444
Bitcoin Blogs 3445
Bitcoin Blogs 3446
Bitcoin Blogs 3447
Bitcoin Blogs 3448
Bitcoin Blogs 3449
Bitcoin Blogs 3450
Bitcoin Blogs 3451
Bitcoin Blogs 3452
Bitcoin Blogs 3453
Bitcoin Blogs 3454
Bitcoin Blogs 3455
Bitcoin Blogs 3456
Bitcoin Blogs 3457
Bitcoin Blogs 3458
Bitcoin Blogs 3459
Bitcoin Blogs 3460
Bitcoin Blogs 3461
Bitcoin Blogs 3462
Bitcoin Blogs 3463
Bitcoin Blogs 3464
Bitcoin Blogs 3465
Bitcoin Blogs 3466
Bitcoin Blogs 3467
Bitcoin Blogs 3468
Bitcoin Blogs 3469
Bitcoin Blogs 3470
Bitcoin Blogs 3471
Bitcoin Blogs 3472
Bitcoin Blogs 3473
Bitcoin Blogs 3474
Bitcoin Blogs 3475
Bitcoin Blogs 3476
Bitcoin Blogs 3477
Bitcoin Blogs 3478
Bitcoin Blogs 3479
Bitcoin Blogs 3480
Bitcoin Blogs 3481
Bitcoin Blogs 3482
Bitcoin Blogs 3483
Bitcoin Blogs 3484
Bitcoin Blogs 3485
Bitcoin Blogs 3486
Bitcoin Blogs 3487
Bitcoin Blogs 3488
Bitcoin Blogs 3489
Bitcoin Blogs 3490
Bitcoin Blogs 3491
Bitcoin Blogs 3492
Bitcoin Blogs 3493
Bitcoin Blogs 3494
Bitcoin Blogs 3495
Bitcoin Blogs 3496
Bitcoin Blogs 3497
Bitcoin Blogs 3498
Bitcoin Blogs 3499
Bitcoin Blogs 3500

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button