Implementation
If you wanted to customize URLs in Drupal 7, you could use the Pathauto module. You can still do that in Drupal 8, but D8’s routing system can be coaxed into doing something similar. It works on admin pages, too, which was perfect for NCYL’s needs.
Overriding Existing Node Paths
As an example, let’s say you have a node type specifically for storing information about schools: a School Node. The standard admin path for adding a School Node would be something like this:
/node/add/school
But, add a custom module with route configuration and you can have this:
/school/add
For simplicity, we’ll call our module school.module. The directory structure looks like this:
modules/
school/
school.module
school.routing.yml
The route configuration sits inside school.routing.yml and looks like this:
school.add:
path: '/school/add'
defaults:
_controller: '\Drupal\node\Controller\NodeController::add'
_title: 'Add School'
node_type: 'school'
requirements:
_node_add_access: 'node:school'
Line by line:
school.add:
This is the name of the route. Route names should be unique and usually start with the name of your module.
path: '/school/add'
The path the route points to. This is the part that comes after your site’s base URL.
_controller: '\Drupal\node\Controller\NodeController::add'
This tells the route to use the NodeController, provided by the Node module. No need for a custom controller here.
_title: 'Add School'
This sets the page title of the node add form.
_node_add_access: 'node:school'
This is an access handler that ensures the user has permission to add a node of type “school.”
Providing a custom path to edit School Nodes is even easier:
school.edit:
path: '/school/{node}/edit'
defaults:
_entity_form: 'node.edit'
requirements:
node: \d+
_entity_access: 'node.update'
We no longer need to tell the route which controller to use or what type of node we’re using. Drupal 8’s Entity API figures it out using the node ID passed in the URL.
Line by line again:
path: '/school/{node}/edit'
The path now contains a placeholder, {node}, which represents the node ID in the URL.
_entity_form: 'node.edit'
The form we want to use to edit the node.
node: \d+
Some validation to ensure the URL contains the right data type for a node ID. By specifying the regular expression pattern \d+
, we are telling Drupal to only use this route when {node}
is one or more digits. The route will match a URL like /school/32/edit, but will not match /school/lincoln-high/edit.
_entity_access: 'node.update'
An access handler, ensuring the user has permission to update this node. No need to specify the node type, as we did when adding a node.
Finally, a route for viewing the node:
school.view:
path: '/school/{node}'
defaults:
_controller: '\Drupal\node\Controller\NodeViewController::view'
requirements:
node: \d+
_entity_access: 'node.view'
Very similar to the node edit route, just with a different path and controller.
For a more thorough explanation of routes and route options not covered here, check out the official docs.
Custom Controllers
What if you want to provide a custom controller for adding a node and still take advantage of Drupal’s permissions system? Routes can do that, too.
Let’s introduce a Teacher Node and an accompanying module.
modules/
school/
teacher/
src/
Controller/
TeacherController.php
teacher.module
teacher.routing.yml
teacher.routing.yml looks like this:
teacher.add:
path: '/teacher/add'
defaults:
_controller: '\Drupal\teacher\Controller\TeacherController::addTeacher'
_title: 'Add Teacher'
node_type: 'teacher'
requirements:
_node_add_access: 'node:teacher'
Very similar to the route we used to add School Nodes, but with a custom controller.
Bitcoin Blogs 1001
Bitcoin Blogs 1002
Bitcoin Blogs 1003
Bitcoin Blogs 1004
Bitcoin Blogs 1005
Bitcoin Blogs 1006
Bitcoin Blogs 1007
Bitcoin Blogs 1008
Bitcoin Blogs 1009
Bitcoin Blogs 1010
Bitcoin Blogs 1011
Bitcoin Blogs 1012
Bitcoin Blogs 1013
Bitcoin Blogs 1014
Bitcoin Blogs 1015
Bitcoin Blogs 1016
Bitcoin Blogs 1017
Bitcoin Blogs 1018
Bitcoin Blogs 1019
Bitcoin Blogs 1020
Bitcoin Blogs 1021
Bitcoin Blogs 1022
Bitcoin Blogs 1023
Bitcoin Blogs 1024
Bitcoin Blogs 1025
Bitcoin Blogs 1026
Bitcoin Blogs 1027
Bitcoin Blogs 1028
Bitcoin Blogs 1029
Bitcoin Blogs 1030
Bitcoin Blogs 1031
Bitcoin Blogs 1032
Bitcoin Blogs 1033
Bitcoin Blogs 1034
Bitcoin Blogs 1035
Bitcoin Blogs 1036
Bitcoin Blogs 1037
Bitcoin Blogs 1038
Bitcoin Blogs 1039
Bitcoin Blogs 1040
Bitcoin Blogs 1041
Bitcoin Blogs 1042
Bitcoin Blogs 1043
Bitcoin Blogs 1044
Bitcoin Blogs 1045
Bitcoin Blogs 1046
Bitcoin Blogs 1047
Bitcoin Blogs 1048
Bitcoin Blogs 1049
Bitcoin Blogs 1050
Bitcoin Blogs 1051
Bitcoin Blogs 1052
Bitcoin Blogs 1053
Bitcoin Blogs 1054
Bitcoin Blogs 1055
Bitcoin Blogs 1056
Bitcoin Blogs 1057
Bitcoin Blogs 1058
Bitcoin Blogs 1059
Bitcoin Blogs 1060
Bitcoin Blogs 1061
Bitcoin Blogs 1062
Bitcoin Blogs 1063
Bitcoin Blogs 1064
Bitcoin Blogs 1065
Bitcoin Blogs 1066
Bitcoin Blogs 1067
Bitcoin Blogs 1068
Bitcoin Blogs 1069
Bitcoin Blogs 1070
Bitcoin Blogs 1071
Bitcoin Blogs 1072
Bitcoin Blogs 1073
Bitcoin Blogs 1074
Bitcoin Blogs 1075
Bitcoin Blogs 1076
Bitcoin Blogs 1077
Bitcoin Blogs 1078
Bitcoin Blogs 1079
Bitcoin Blogs 1080
Bitcoin Blogs 1081
Bitcoin Blogs 1082
Bitcoin Blogs 1083
Bitcoin Blogs 1084
Bitcoin Blogs 1085
Bitcoin Blogs 1086
Bitcoin Blogs 1087
Bitcoin Blogs 1088
Bitcoin Blogs 1089
Bitcoin Blogs 1090
Bitcoin Blogs 1091
Bitcoin Blogs 1092
Bitcoin Blogs 1093
Bitcoin Blogs 1094
Bitcoin Blogs 1095
Bitcoin Blogs 1096
Bitcoin Blogs 1097
Bitcoin Blogs 1098
Bitcoin Blogs 1099
Bitcoin Blogs 1100
Bitcoin Blogs 1101
Bitcoin Blogs 1102
Bitcoin Blogs 1103
Bitcoin Blogs 1104
Bitcoin Blogs 1105
Bitcoin Blogs 1106
Bitcoin Blogs 1107
Bitcoin Blogs 1108
Bitcoin Blogs 1109
Bitcoin Blogs 1110
Bitcoin Blogs 1111
Bitcoin Blogs 1112
Bitcoin Blogs 1113
Bitcoin Blogs 1114
Bitcoin Blogs 1115
Bitcoin Blogs 1116
Bitcoin Blogs 1117
Bitcoin Blogs 1118
Bitcoin Blogs 1119
Bitcoin Blogs 1120
Bitcoin Blogs 1121
Bitcoin Blogs 1122
Bitcoin Blogs 1123
Bitcoin Blogs 1124
Bitcoin Blogs 1125
Bitcoin Blogs 1126
Bitcoin Blogs 1127
Bitcoin Blogs 1128
Bitcoin Blogs 1129
Bitcoin Blogs 1130
Bitcoin Blogs 1131
Bitcoin Blogs 1132
Bitcoin Blogs 1133
Bitcoin Blogs 1134
Bitcoin Blogs 1135
Bitcoin Blogs 1136
Bitcoin Blogs 1137
Bitcoin Blogs 1138
Bitcoin Blogs 1139
Bitcoin Blogs 1140
Bitcoin Blogs 1141
Bitcoin Blogs 1142
Bitcoin Blogs 1143
Bitcoin Blogs 1144
Bitcoin Blogs 1145
Bitcoin Blogs 1146
Bitcoin Blogs 1147
Bitcoin Blogs 1148
Bitcoin Blogs 1149
Bitcoin Blogs 1150
Bitcoin Blogs 1151
Bitcoin Blogs 1152
Bitcoin Blogs 1153
Bitcoin Blogs 1154
Bitcoin Blogs 1155
Bitcoin Blogs 1156
Bitcoin Blogs 1157
Bitcoin Blogs 1158
Bitcoin Blogs 1159
Bitcoin Blogs 1160
Bitcoin Blogs 1161
Bitcoin Blogs 1162
Bitcoin Blogs 1163
Bitcoin Blogs 1164
Bitcoin Blogs 1165
Bitcoin Blogs 1166
Bitcoin Blogs 1167
Bitcoin Blogs 1168
Bitcoin Blogs 1169
Bitcoin Blogs 1170
Bitcoin Blogs 1171
Bitcoin Blogs 1172
Bitcoin Blogs 1173
Bitcoin Blogs 1174
Bitcoin Blogs 1175
Bitcoin Blogs 1176
Bitcoin Blogs 1177
Bitcoin Blogs 1178
Bitcoin Blogs 1179
Bitcoin Blogs 1180
Bitcoin Blogs 1181
Bitcoin Blogs 1182
Bitcoin Blogs 1183
Bitcoin Blogs 1184
Bitcoin Blogs 1185
Bitcoin Blogs 1186
Bitcoin Blogs 1187
Bitcoin Blogs 1188
Bitcoin Blogs 1189
Bitcoin Blogs 1190
Bitcoin Blogs 1191
Bitcoin Blogs 1192
Bitcoin Blogs 1193
Bitcoin Blogs 1194
Bitcoin Blogs 1195
Bitcoin Blogs 1196
Bitcoin Blogs 1197
Bitcoin Blogs 1198
Bitcoin Blogs 1199
Bitcoin Blogs 1200
Bitcoin Blogs 1201
Bitcoin Blogs 1202
Bitcoin Blogs 1203
Bitcoin Blogs 1204
Bitcoin Blogs 1205
Bitcoin Blogs 1206
Bitcoin Blogs 1207
Bitcoin Blogs 1208
Bitcoin Blogs 1209
Bitcoin Blogs 1210
Bitcoin Blogs 1211
Bitcoin Blogs 1212
Bitcoin Blogs 1213
Bitcoin Blogs 1214
Bitcoin Blogs 1215
Bitcoin Blogs 1216
Bitcoin Blogs 1217
Bitcoin Blogs 1218
Bitcoin Blogs 1219
Bitcoin Blogs 1220
Bitcoin Blogs 1221
Bitcoin Blogs 1222
Bitcoin Blogs 1223
Bitcoin Blogs 1224
Bitcoin Blogs 1225
Bitcoin Blogs 1226
Bitcoin Blogs 1227
Bitcoin Blogs 1228
Bitcoin Blogs 1229
Bitcoin Blogs 1230
Bitcoin Blogs 1231
Bitcoin Blogs 1232
Bitcoin Blogs 1233
Bitcoin Blogs 1234
Bitcoin Blogs 1235
Bitcoin Blogs 1236
Bitcoin Blogs 1237
Bitcoin Blogs 1238
Bitcoin Blogs 1239
Bitcoin Blogs 1240
Bitcoin Blogs 1241
Bitcoin Blogs 1242
Bitcoin Blogs 1243
Bitcoin Blogs 1244
Bitcoin Blogs 1245
Bitcoin Blogs 1246
Bitcoin Blogs 1247
Bitcoin Blogs 1248
Bitcoin Blogs 1249
Bitcoin Blogs 1250
Bitcoin Blogs 1251
Bitcoin Blogs 1252
Bitcoin Blogs 1253
Bitcoin Blogs 1254
Bitcoin Blogs 1255
Bitcoin Blogs 1256
Bitcoin Blogs 1257
Bitcoin Blogs 1258
Bitcoin Blogs 1259
Bitcoin Blogs 1260
Bitcoin Blogs 1261
Bitcoin Blogs 1262
Bitcoin Blogs 1263
Bitcoin Blogs 1264
Bitcoin Blogs 1265
Bitcoin Blogs 1266
Bitcoin Blogs 1267
Bitcoin Blogs 1268
Bitcoin Blogs 1269
Bitcoin Blogs 1270
Bitcoin Blogs 1271
Bitcoin Blogs 1272
Bitcoin Blogs 1273
Bitcoin Blogs 1274
Bitcoin Blogs 1275
Bitcoin Blogs 1276
Bitcoin Blogs 1277
Bitcoin Blogs 1278
Bitcoin Blogs 1279
Bitcoin Blogs 1280
Bitcoin Blogs 1281
Bitcoin Blogs 1282
Bitcoin Blogs 1283
Bitcoin Blogs 1284
Bitcoin Blogs 1285
Bitcoin Blogs 1286
Bitcoin Blogs 1287
Bitcoin Blogs 1288
Bitcoin Blogs 1289
Bitcoin Blogs 1290
Bitcoin Blogs 1291
Bitcoin Blogs 1292
Bitcoin Blogs 1293
Bitcoin Blogs 1294
Bitcoin Blogs 1295
Bitcoin Blogs 1296
Bitcoin Blogs 1297
Bitcoin Blogs 1298
Bitcoin Blogs 1299
Bitcoin Blogs 1300
Bitcoin Blogs 1301
Bitcoin Blogs 1302
Bitcoin Blogs 1303
Bitcoin Blogs 1304
Bitcoin Blogs 1305
Bitcoin Blogs 1306
Bitcoin Blogs 1307
Bitcoin Blogs 1308
Bitcoin Blogs 1309
Bitcoin Blogs 1310
Bitcoin Blogs 1311
Bitcoin Blogs 1312
Bitcoin Blogs 1313
Bitcoin Blogs 1314
Bitcoin Blogs 1315
Bitcoin Blogs 1316
Bitcoin Blogs 1317
Bitcoin Blogs 1318
Bitcoin Blogs 1319
Bitcoin Blogs 1320
Bitcoin Blogs 1321
Bitcoin Blogs 1322
Bitcoin Blogs 1323
Bitcoin Blogs 1324
Bitcoin Blogs 1325
Bitcoin Blogs 1326
Bitcoin Blogs 1327
Bitcoin Blogs 1328
Bitcoin Blogs 1329
Bitcoin Blogs 1330
Bitcoin Blogs 1331
Bitcoin Blogs 1332
Bitcoin Blogs 1333
Bitcoin Blogs 1334
Bitcoin Blogs 1335
Bitcoin Blogs 1336
Bitcoin Blogs 1337
Bitcoin Blogs 1338
Bitcoin Blogs 1339
Bitcoin Blogs 1340
Bitcoin Blogs 1341
Bitcoin Blogs 1342
Bitcoin Blogs 1343
Bitcoin Blogs 1344
Bitcoin Blogs 1345
Bitcoin Blogs 1346
Bitcoin Blogs 1347
Bitcoin Blogs 1348
Bitcoin Blogs 1349
Bitcoin Blogs 1350
Bitcoin Blogs 1351
Bitcoin Blogs 1352
Bitcoin Blogs 1353
Bitcoin Blogs 1354
Bitcoin Blogs 1355
Bitcoin Blogs 1356
Bitcoin Blogs 1357
Bitcoin Blogs 1358
Bitcoin Blogs 1359
Bitcoin Blogs 1360
Bitcoin Blogs 1361
Bitcoin Blogs 1362
Bitcoin Blogs 1363
Bitcoin Blogs 1364
Bitcoin Blogs 1365
Bitcoin Blogs 1366
Bitcoin Blogs 1367
Bitcoin Blogs 1368
Bitcoin Blogs 1369
Bitcoin Blogs 1370
Bitcoin Blogs 1371
Bitcoin Blogs 1372
Bitcoin Blogs 1373
Bitcoin Blogs 1374
Bitcoin Blogs 1375
Bitcoin Blogs 1376
Bitcoin Blogs 1377
Bitcoin Blogs 1378
Bitcoin Blogs 1379
Bitcoin Blogs 1380
Bitcoin Blogs 1381
Bitcoin Blogs 1382
Bitcoin Blogs 1383
Bitcoin Blogs 1384
Bitcoin Blogs 1385
Bitcoin Blogs 1386
Bitcoin Blogs 1387
Bitcoin Blogs 1388
Bitcoin Blogs 1389
Bitcoin Blogs 1390
Bitcoin Blogs 1391
Bitcoin Blogs 1392
Bitcoin Blogs 1393
Bitcoin Blogs 1394
Bitcoin Blogs 1395
Bitcoin Blogs 1396
Bitcoin Blogs 1397
Bitcoin Blogs 1398
Bitcoin Blogs 1399
Bitcoin Blogs 1400
Bitcoin Blogs 1401
Bitcoin Blogs 1402
Bitcoin Blogs 1403
Bitcoin Blogs 1404
Bitcoin Blogs 1405
Bitcoin Blogs 1406
Bitcoin Blogs 1407
Bitcoin Blogs 1408
Bitcoin Blogs 1409
Bitcoin Blogs 1410
Bitcoin Blogs 1411
Bitcoin Blogs 1412
Bitcoin Blogs 1413
Bitcoin Blogs 1414
Bitcoin Blogs 1415
Bitcoin Blogs 1416
Bitcoin Blogs 1417
Bitcoin Blogs 1418
Bitcoin Blogs 1419
Bitcoin Blogs 1420
Bitcoin Blogs 1421
Bitcoin Blogs 1422
Bitcoin Blogs 1423
Bitcoin Blogs 1424
Bitcoin Blogs 1425
Bitcoin Blogs 1426
Bitcoin Blogs 1427
Bitcoin Blogs 1428
Bitcoin Blogs 1429
Bitcoin Blogs 1430
Bitcoin Blogs 1431
Bitcoin Blogs 1432
Bitcoin Blogs 1433
Bitcoin Blogs 1434
Bitcoin Blogs 1435
Bitcoin Blogs 1436
Bitcoin Blogs 1437
Bitcoin Blogs 1438
Bitcoin Blogs 1439
Bitcoin Blogs 1440
Bitcoin Blogs 1441
Bitcoin Blogs 1442
Bitcoin Blogs 1443
Bitcoin Blogs 1444
Bitcoin Blogs 1445
Bitcoin Blogs 1446
Bitcoin Blogs 1447
Bitcoin Blogs 1448
Bitcoin Blogs 1449
Bitcoin Blogs 1450
Bitcoin Blogs 1451
Bitcoin Blogs 1452
Bitcoin Blogs 1453
Bitcoin Blogs 1454
Bitcoin Blogs 1455
Bitcoin Blogs 1456
Bitcoin Blogs 1457
Bitcoin Blogs 1458
Bitcoin Blogs 1459
Bitcoin Blogs 1460
Bitcoin Blogs 1461
Bitcoin Blogs 1462
Bitcoin Blogs 1463
Bitcoin Blogs 1464
Bitcoin Blogs 1465
Bitcoin Blogs 1466
Bitcoin Blogs 1467
Bitcoin Blogs 1468
Bitcoin Blogs 1469
Bitcoin Blogs 1470
Bitcoin Blogs 1471
Bitcoin Blogs 1472
Bitcoin Blogs 1473
Bitcoin Blogs 1474
Bitcoin Blogs 1475
Bitcoin Blogs 1476
Bitcoin Blogs 1477
Bitcoin Blogs 1478
Bitcoin Blogs 1479
Bitcoin Blogs 1480
Bitcoin Blogs 1481
Bitcoin Blogs 1482
Bitcoin Blogs 1483
Bitcoin Blogs 1484
Bitcoin Blogs 1485
Bitcoin Blogs 1486
Bitcoin Blogs 1487
Bitcoin Blogs 1488
Bitcoin Blogs 1489
Bitcoin Blogs 1490
Bitcoin Blogs 1491
Bitcoin Blogs 1492
Bitcoin Blogs 1493
Bitcoin Blogs 1494
Bitcoin Blogs 1495
Bitcoin Blogs 1496
Bitcoin Blogs 1497
Bitcoin Blogs 1498
Bitcoin Blogs 1499
Bitcoin Blogs 1500