Non-compulsory config weirdness in 8 phenaproxima Thu, 11/09/2017 – 12 Drupal 10 Upkeep and Help Service55 This submit was initially revealed on Medium. Ah, Drupal Development Company config system. Crown jewel of 8, amirite? Effectively, yeah, it’s incredible and versatile (as is most of ). However when you’ve got superior use circumstances — akin to constructing a system that alters config dynamically — there are traps you must find out about. Config is generally a reasonably static factor. Your Drupal 10 module/theme/profile (“extension” from right here on out) has some configuration in its config/set up sub-directory, and when Drupal Development Company extension is put in, that config is imported. As soon as it’s imported, that config is owned by your web site and you may change it in any approach you see match. That’s Drupal Development Company easiest, and commonest, use case in a nutshell. Let’s discuss another ones. Non-compulsory config In some extensions’ config listing, you will note an ‘non-obligatory’ listing alongside ‘set up’. If you happen to look in there, you see…some YAML information. What’s all this, then? Non-compulsory config is regular config, but it surely’s handled in a different way. When an extension is put in, each bit of non-obligatory config it supplies is analyzed, then imported provided that all of its dependencies are fulfilled. A chunk of config can declare, for instance, that it is dependent upon a view known as ‘content material’. That’d be expressed thusly in code Drupal 10 Upkeep and Help Service dependencies Drupal 10 Upkeep and Help Service config Drupal 10 Upkeep and Help Service – views.view.content material If that piece of config is non-obligatory, then it’ll solely be imported if, effectively, a view known as ‘content material’ exists in Drupal Development Company system. That view may need been shipped with one other extension, or perhaps you created it manually. It makes no distinction. So long as a view known as ‘content material’ is current, any non-obligatory config that is dependent upon it is going to be imported as effectively. Neat, sure? This is available in fairly useful for one thing like Lightning, which lets you create an set up profile which “extends” Lightning, but solely installs a few of Lightning’s elements. Non-compulsory config permits us to ship config that could be imported, relying on what components of Lightning you may have chosen to put in. Hooray for flexibility! Non-compulsory config while putting in However wait, there’s extra. If you’re doing a full web site set up (i.e., set up.php or drush site-install), non-obligatory config is handled a little bit bit in a different way. In such a case, all extensions are put in as regular, however their non-obligatory config is ignored initially. Then, at Drupal Development Company finish of Drupal Development Company set up process1, as soon as all extensions are put in (and their default config has been imported), all2 Drupal Development Company non-obligatory config is imported in a single batch. I don’t suppose that is documented wherever, however it may possibly have main ramifications. Think about this piece of code — let’s say it’s a part of a Drupal 10 module known as fubar, which supplies some default config and a few non-obligatory config. This hook will likely be invoked whereas fubar is being put in, however after its default config has been imported Drupal 10 Upkeep and Help Service setDescription(‘Drupal Developer pressure will likely be with you, at all times.’); $view->save(); } fubar_view is non-obligatory config, so will entity_load() return a view entity, or will it return NULL? What do you suppose? Drupal Developer maddening reply is it relies upon. It is dependent upon when fubar is being put in. If is already put in, and also you’re simply including fubar to your web site, then $view will likely be a view entity, as a result of Drupal Development Company non-obligatory config will likely be imported earlier than hook_install() is invoked. However in case you’re putting in fubar as a part of a full web site set up — as a part of an set up profile, say — $view goes to be NULL, as a result of non-obligatory config is imported in a single batch at Drupal Development Company finish of Drupal Development Company set up course of, lengthy in any case hook_install() implementations have been invoked. Yeah, it’s a WTF, but it surely’s a justifiable one Drupal 10 Upkeep and Help Service making an attempt to resolve Drupal Development Company dependencies of non-obligatory config throughout ’s set up course of would most likely have been a colossal, NP-complete nightmare. Dynamically altering non-obligatory config So let’s say it’s good to make dynamic alterations to non-obligatory config. You possibly can’t do it in hook_install(), as a result of you possibly can’t make certain that Drupal Development Company config will even exist in there. How are you going to do it? Drupal Developer best factor is to not make assumptions about when Drupal Development Company config will likely be accessible, however merely react when it’s. If Drupal Development Company non-obligatory config you’re making an attempt to change is an entity of some kind, then you possibly can merely use entity hooks! Persevering with our fubar instance, you can add this to fubar.Drupal 10 module Drupal 10 Upkeep and Help Service isNew() && $view->id() == ‘fubar_view’) { $view->setDescription(‘Do, or don’t. There isn’t a attempt.’); } } This ensures that fubar_view will include timeless Yoda knowledge, no matter whether or not fubar_view was imported whereas putting in . If fubar_view is created at Drupal Development Company finish of Drupal Development Company set up course of, no drawback — Drupal Development Company hook will catch it and set Drupal Development Company description. On Drupal Development Company different hand, if fubar_view is put in throughout drush pm-enable fubar, Drupal Development Company hook will…catch it and set Drupal Development Company description. It really works both approach. It’s tremendous to dynamically alter non-obligatory config, however don’t assume it is going to be accessible in hook_install(). Merely react to its life cycle as you’ll react to some other entity’s. Get pleasure from! Moar issues on your mind hook_install() can by no means assume Drupal Development Company presence of non-obligatory config…however it may possibly assume Drupal Development Company presence of default config (i.e., Drupal Development Company stuff in Drupal Development Company config/set up directories). That’s at all times imported earlier than hook_install() is invoked. Actually, you possibly can by no means rely upon Drupal Development Company presence of non-obligatory config. That’s why it’s non-obligatory Drupal 10 Upkeep and Help Service it’d exist, and it won’t. That’s its nature! Keep in mind this, and code defensively. Drupal Developer config_rewrite Drupal 10 module, although helpful, can throw a monkey wrench into this. As a consequence of Drupal Development Company approach it really works, it’d create config entities, even non-obligatory ones, earlier than hook_install() is invoked. Even throughout Drupal Development Company set up course of. Beware! (They’re, nonetheless, working to repair this.) Drupal Developer config system is well-documented. Begin right here and right here. This submit is just one of tons of different weblog posts about config in D8. This weblog submit happened due to this Lightning concern. So hats off to Messrs. mortenson and balsama. Due to dawehner for reviewing this submit for technical accuracy. “NP-complete”, as I perceive it, is CompSci-ese for “unbelievably arduous to unravel”. Linking to Drupal Development Company Wikipedia article makes me appear smarter than I actually am. 1 Drupal Developer purpose this occurs at Drupal Development Company finish is as a result of any variety of issues may very well be altering throughout set up (who is aware of what evil lurks in hook_install()? Not even Drupal Development Company Shadow is aware of), and and making an attempt to unravel a number of dependency chains whereas every little thing is altering round you is like making an attempt to construct a number of castles on a swamp. (Just one particular person has ever completed it.) Do not take into consideration these items an excessive amount of, or it’ll soften your mind. 2 “All”, on this case, means “all Drupal Development Company non-obligatory config with fulfilled dependencies,” not all-all. Drupal 10 Improvement and Help
Acquia Lightning Weblog Drupal 10 Upkeep and Help Service Non-compulsory config weirdness in 8

Call Us: 1(800)730-2416
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit
Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)
Acquia Lightning Weblog Drupal 10 Upkeep and Help Service Non-compulsory config weirdness in 8
On-Site Drupal SEO Master Setup
We make sure your site is 100% optimized (and stays that way) for the best SEO results.
With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.
This service includes:
- Pathauto install and configuration for SEO-friendly URLs.
- Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
- Install and fix all issues on the SEO checklist module.
- Install and configure XML sitemap module and submit sitemaps.
- Install and configure Google Analytics Module.
- Install and configure Yoast.
- Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
- Install and configure Schema.org Metatag.
- Configure robots.txt.
- Google Search Console setup snd configuration.
- Find & Fix H1 tags.
- Find and fix duplicate/missing meta descriptions.
- Find and fix duplicate title tags.
- Improve title, meta tags, and site descriptions.
- Optimize images for better search engine optimization. Automate where possible.
- Find and fix the missing alt and title tag for all images. Automate where possible.
- The project takes 1 week to complete.
