<iframe src=”https://prezi.com/3m8yspw-7cwx/configuration-in-drupal-8/” width=”100%”></iframe> <p>Source: <a href=”//internetdevels.com/blog/configuration-in-drupal-8″>InternetDevels.com</a></p> |
In one of the recent blog posts by our developer, we offered you Drupal 8 development tips. Today, we’ll discuss working with configuration in Drupal 8. Real profit for Drupal developers by the same author. Enjoy! 😉
Drupal 8 offers a new configuration data saving system. It is useful for Drupal developers because it facilitates configuration import and export.
The configuration by default comes with modules and themes and is saved in YAML files (eg: image.settings.yml), and when the module or the theme is enabled, the configuration is imported to the active configuration repository. By default, the active configuration is saved in the database. The Drupal 8 core includes the Configuration Manager module.
The Drupal 8 Configuration Manager module
This module provides us with a user interface for configuration changes import and export. Configuration Manager makes it possible to deploy configuration from one environment in another – provided that it is the same site. The site is identified with the help of a universally unique identifier (UUID). The Configuration Manager module eliminates the need for additional modules such as Features and Strongarm.
In Drupal 7, to move content type etc., you had to download Features, make settings, and now you just need to paste the copied configuration to get the required content type.
Configuration Manager enables you to:
- synchronize configuration;
- make one-time import/export;
- make full import/export.
Making configuration changes on a live site is not the best idea. The aim of the configuration system in Drupal 8 is to enable you to make various settings on your test site and move only the ready settings to your live site.
The Configuration Manager page can be found here Manage > Configuration > Development > Configuration management або admin/config/development/configuration.
Configuration import and export in Drupal 8
For one-time export form test to live site you need to do the following:
- select the Export tab (1);
- select the configuration type (2);
- select the required configuration (3);
- copy the configuration text (4)
For one-time export of the previously imported configuration, you need to do the following:
- select the Import tab (1);
- select the configuration type (2);
- paste the configuration text (3);
- press the Import button (4).
For full configuration export, you need to select the “Full Import/Export”(1) tab, then the “Export”(2) tab. After that you just need to press the Export(3) button. After these actions, the uploading of the archive with the configuration will begin in the browser.
To import the newly uploaded configuration, you need to do the following:
- select the “Full Import/Export”(1) tab
- select the “Export”(2) tab
- select the archive file(3) and press the Upload(4) button
By default, Drupal 8 saves configuration files in these folders:
- ‘sites/default/files/config/active’
- ‘sites/default/files/config/staging’
You can change the configuration saving place in the settings.php file. To do this, you need to go to
$config_directories[‘active’] = ‘your_path’ та $config_directories[‘active’] = ‘your_path’ and specify the required path.
Drupal 8 provides us with a powerful API to work with configuration via the code.
On the next step, I will show how to programmatically create, modify, and delete the settings.
Examples of working with configuration in Drupal 8
Now let’s consider working with configuration on our example module.
In Drupal 7, one of the most common ways to save the settings was using variable_get() and variable_set(). In Drupal 8, they are replaced with a new configuration system. The variable_get()/variable_set() functions were removed from Drupal 8. You should work with the settings in the following way:
$config = \Drupal::configFactory()->getEditable($key) – getting the necessary configuration.
$configuration->set($key , $value ) – setting the necessary value.
$configuration->save() – saving the changes.
Learn More 2001
Learn More 2002
Learn More 2003
Learn More 2004
Learn More 2005
Learn More 2006
Learn More 2007
Learn More 2008
Learn More 2009
Learn More 2010
Learn More 2011
Learn More 2012
Learn More 2013
Learn More 2014
Learn More 2015
Learn More 2016
Learn More 2017
Learn More 2018
Learn More 2019
Learn More 2020
Learn More 2021
Learn More 2022
Learn More 2023
Learn More 2024
Learn More 2025
Learn More 2026
Learn More 2027
Learn More 2028
Learn More 2029
Learn More 2030
Learn More 2031
Learn More 2032
Learn More 2033
Learn More 2034
Learn More 2035
Learn More 2036
Learn More 2037
Learn More 2038
Learn More 2039
Learn More 2040
Learn More 2041
Learn More 2042
Learn More 2043
Learn More 2044
Learn More 2045
Learn More 2046
Learn More 2047
Learn More 2048
Learn More 2049
Learn More 2050
Learn More 2051
Learn More 2052
Learn More 2053
Learn More 2054
Learn More 2055
Learn More 2056
Learn More 2057
Learn More 2058
Learn More 2059
Learn More 2060
Learn More 2061
Learn More 2062
Learn More 2063
Learn More 2064
Learn More 2065
Learn More 2066
Learn More 2067
Learn More 2068
Learn More 2069
Learn More 2070
Learn More 2071
Learn More 2072
Learn More 2073
Learn More 2074
Learn More 2075
Learn More 2076
Learn More 2077
Learn More 2078
Learn More 2079
Learn More 2080
Learn More 2081
Learn More 2082
Learn More 2083
Learn More 2084
Learn More 2085
Learn More 2086
Learn More 2087
Learn More 2088
Learn More 2089
Learn More 2090
Learn More 2091
Learn More 2092
Learn More 2093
Learn More 2094
Learn More 2095
Learn More 2096
Learn More 2097
Learn More 2098
Learn More 2099
Learn More 2100
Learn More 2101
Learn More 2102
Learn More 2103
Learn More 2104
Learn More 2105
Learn More 2106
Learn More 2107
Learn More 2108
Learn More 2109
Learn More 2110
Learn More 2111
Learn More 2112
Learn More 2113
Learn More 2114
Learn More 2115
Learn More 2116
Learn More 2117
Learn More 2118
Learn More 2119
Learn More 2120
Learn More 2121
Learn More 2122
Learn More 2123
Learn More 2124
Learn More 2125
Learn More 2126
Learn More 2127
Learn More 2128
Learn More 2129
Learn More 2130
Learn More 2131
Learn More 2132
Learn More 2133
Learn More 2134
Learn More 2135
Learn More 2136
Learn More 2137
Learn More 2138
Learn More 2139
Learn More 2140
Learn More 2141
Learn More 2142
Learn More 2143
Learn More 2144
Learn More 2145
Learn More 2146
Learn More 2147
Learn More 2148
Learn More 2149
Learn More 2150
Learn More 2151
Learn More 2152
Learn More 2153
Learn More 2154
Learn More 2155
Learn More 2156
Learn More 2157
Learn More 2158
Learn More 2159
Learn More 2160
Learn More 2161
Learn More 2162
Learn More 2163
Learn More 2164
Learn More 2165
Learn More 2166
Learn More 2167
Learn More 2168
Learn More 2169
Learn More 2170
Learn More 2171
Learn More 2172
Learn More 2173
Learn More 2174
Learn More 2175
Learn More 2176
Learn More 2177
Learn More 2178
Learn More 2179
Learn More 2180
Learn More 2181
Learn More 2182
Learn More 2183
Learn More 2184
Learn More 2185
Learn More 2186
Learn More 2187
Learn More 2188
Learn More 2189
Learn More 2190
Learn More 2191
Learn More 2192
Learn More 2193
Learn More 2194
Learn More 2195
Learn More 2196
Learn More 2197
Learn More 2198
Learn More 2199
Learn More 2200
Learn More 2201
Learn More 2202
Learn More 2203
Learn More 2204
Learn More 2205
Learn More 2206
Learn More 2207
Learn More 2208
Learn More 2209
Learn More 2210
Learn More 2211
Learn More 2212
Learn More 2213
Learn More 2214
Learn More 2215
Learn More 2216
Learn More 2217
Learn More 2218
Learn More 2219
Learn More 2220
Learn More 2221
Learn More 2222
Learn More 2223
Learn More 2224
Learn More 2225
Learn More 2226
Learn More 2227
Learn More 2228
Learn More 2229
Learn More 2230
Learn More 2231
Learn More 2232
Learn More 2233
Learn More 2234
Learn More 2235
Learn More 2236
Learn More 2237
Learn More 2238
Learn More 2239
Learn More 2240
Learn More 2241
Learn More 2242
Learn More 2243
Learn More 2244
Learn More 2245
Learn More 2246
Learn More 2247
Learn More 2248
Learn More 2249
Learn More 2250
Learn More 2251
Learn More 2252
Learn More 2253
Learn More 2254
Learn More 2255
Learn More 2256
Learn More 2257
Learn More 2258
Learn More 2259
Learn More 2260
Learn More 2261
Learn More 2262
Learn More 2263
Learn More 2264
Learn More 2265
Learn More 2266
Learn More 2267
Learn More 2268
Learn More 2269
Learn More 2270
Learn More 2271
Learn More 2272
Learn More 2273
Learn More 2274
Learn More 2275
Learn More 2276
Learn More 2277
Learn More 2278
Learn More 2279
Learn More 2280
Learn More 2281
Learn More 2282
Learn More 2283
Learn More 2284
Learn More 2285
Learn More 2286
Learn More 2287
Learn More 2288
Learn More 2289
Learn More 2290
Learn More 2291
Learn More 2292
Learn More 2293
Learn More 2294
Learn More 2295
Learn More 2296
Learn More 2297
Learn More 2298
Learn More 2299
Learn More 2300
Learn More 2301
Learn More 2302
Learn More 2303
Learn More 2304
Learn More 2305
Learn More 2306
Learn More 2307
Learn More 2308
Learn More 2309
Learn More 2310
Learn More 2311
Learn More 2312
Learn More 2313
Learn More 2314
Learn More 2315
Learn More 2316
Learn More 2317
Learn More 2318
Learn More 2319
Learn More 2320
Learn More 2321
Learn More 2322
Learn More 2323
Learn More 2324
Learn More 2325
Learn More 2326
Learn More 2327
Learn More 2328
Learn More 2329
Learn More 2330
Learn More 2331
Learn More 2332
Learn More 2333
Learn More 2334
Learn More 2335
Learn More 2336
Learn More 2337
Learn More 2338
Learn More 2339
Learn More 2340
Learn More 2341
Learn More 2342
Learn More 2343
Learn More 2344
Learn More 2345
Learn More 2346
Learn More 2347
Learn More 2348
Learn More 2349
Learn More 2350
Learn More 2351
Learn More 2352
Learn More 2353
Learn More 2354
Learn More 2355
Learn More 2356
Learn More 2357
Learn More 2358
Learn More 2359
Learn More 2360
Learn More 2361
Learn More 2362
Learn More 2363
Learn More 2364
Learn More 2365
Learn More 2366
Learn More 2367
Learn More 2368
Learn More 2369
Learn More 2370
Learn More 2371
Learn More 2372
Learn More 2373
Learn More 2374
Learn More 2375
Learn More 2376
Learn More 2377
Learn More 2378
Learn More 2379
Learn More 2380
Learn More 2381
Learn More 2382
Learn More 2383
Learn More 2384
Learn More 2385
Learn More 2386
Learn More 2387
Learn More 2388
Learn More 2389
Learn More 2390
Learn More 2391
Learn More 2392
Learn More 2393
Learn More 2394
Learn More 2395
Learn More 2396
Learn More 2397
Learn More 2398
Learn More 2399
Learn More 2400
Learn More 2401
Learn More 2402
Learn More 2403
Learn More 2404
Learn More 2405
Learn More 2406
Learn More 2407
Learn More 2408
Learn More 2409
Learn More 2410
Learn More 2411
Learn More 2412
Learn More 2413
Learn More 2414
Learn More 2415
Learn More 2416
Learn More 2417
Learn More 2418
Learn More 2419
Learn More 2420
Learn More 2421
Learn More 2422
Learn More 2423
Learn More 2424
Learn More 2425
Learn More 2426
Learn More 2427
Learn More 2428
Learn More 2429
Learn More 2430
Learn More 2431
Learn More 2432
Learn More 2433
Learn More 2434
Learn More 2435
Learn More 2436
Learn More 2437
Learn More 2438
Learn More 2439
Learn More 2440
Learn More 2441
Learn More 2442
Learn More 2443
Learn More 2444
Learn More 2445
Learn More 2446
Learn More 2447
Learn More 2448
Learn More 2449
Learn More 2450
Learn More 2451
Learn More 2452
Learn More 2453
Learn More 2454
Learn More 2455
Learn More 2456
Learn More 2457
Learn More 2458
Learn More 2459
Learn More 2460
Learn More 2461
Learn More 2462
Learn More 2463
Learn More 2464
Learn More 2465
Learn More 2466
Learn More 2467
Learn More 2468
Learn More 2469
Learn More 2470
Learn More 2471
Learn More 2472
Learn More 2473
Learn More 2474
Learn More 2475
Learn More 2476
Learn More 2477
Learn More 2478
Learn More 2479
Learn More 2480
Learn More 2481
Learn More 2482
Learn More 2483
Learn More 2484
Learn More 2485
Learn More 2486
Learn More 2487
Learn More 2488
Learn More 2489
Learn More 2490
Learn More 2491
Learn More 2492
Learn More 2493
Learn More 2494
Learn More 2495
Learn More 2496
Learn More 2497
Learn More 2498
Learn More 2499
Learn More 2500