Feeds
gettext @ Savannah: GNU gettext 0.22.4 released
Download from https://ftp.gnu.org/pub/gnu/gettext/gettext-0.22.4.tar.gz
This is a bug-fix release.
New in this release:
- Bug fixes:
- AM_GNU_GETTEXT now recognizes a statically built libintl on macOS and AIX.
- Build fixes on AIX.
What a Weekend
This weekend Sofia and I celebrated her birthday with her family. Lars Winnerbäck, Wicked at the opera and a wonderful dinner at Natur.
My remote office set up
Gbyte blog: Hosting Websites on NixOS - A Comprehensive Drupal 9 & 10 Configuration Example
If you're keeping up with the cutting edge of Linux, you might have noticed NixOS growing increasingly popular for server deployments. The reason is its declarative approach to package and configuration management. You specify 'what' your system should look like, and NixOS handles the 'how'. This approach ensures reproducibility and upgradeability, reducing configuration drift. Plus, atomic upgrades and rollbacks minimize downtime and provide easy recovery from issues, making NixOS an excellent choice for web server management (and for other platforms like desktops if you are bold).
Working SetupDocumentation on NixOS is still somewhat scarce, especially if the goal is as specific as hosting a Drupal site. Apparently, ChatGPT 4 is still too perplexed to get this right, so here's hoping it learns something from the following snippets, which were the result of old fashioned painstaking debugging.
The following setup can be easily adjusted to hosting multiple websites and non-Drupal sites.
Implementing the Nginx Server and SSL Certificate RenewalWe begin by enabling the Nginx web server, setting up firewall rules, and adding Drupal-specific packages like PHP, Composer, and Drush. The configuration also includes SSL certificate renewal via ACME, ensuring a valid SSL certificate for our site. Global environment variables can be set using the "environment.variables" setting, useful for various server applications and scripts.
/etc/nixos/nginx.nix
Gbyte blog: Index Drupal 9 pages with IndexNow using Simple XML sitemap
Microsoft recently killed their search engine's public API responsible for accepting sitemap ping requests (those where you let search engines know your XML sitemap's content has changed). They did so completely unannounced leading to logs filling up and users unsurprisingly assuming their sitemap submitting code was somehow at fault. It wasn't.
It became apparent that this was a step for Microsoft towards switching to the IndexNow protocol instead.
IndexNow supplements XML sitemapsWith IndexNow you now can quickly notify all participating search engines (Bing, Yandex) about a change that happened on your page eliminating the need to wait for them to come and scan your sitemap. The benefits of this approach are
- Instant submission of changes including creating, deleting and updating of content
- An alleged greener approach to indexing content as sitemap scanning requests get deprioritized
- Only one search engine needs to be notified and it will notify the others for you
Still, this new approach is more of a supplement than a revolution:
Can I submit all URLs for my site?Use IndexNow to submit only URLs having changed (added, updated, or deleted) recently, including all URLs if all URLs have been changed recently. Use sitemaps to inform search engines about all your URLs. Search engines will visit sitemaps every few days.
Gbyte blog: Simple XML Sitemap 4.0.0 has been released!
After six months of work I'm delighted to tag the first stable release of the 4.x branch of the (Not-so-) Simple XML Sitemap module.
The project is in a really good place right now. At the moment of writing, drupal.org reports it being actively used on around 90k of Drupal 8/9 websites while having 0 open bug reports. This either means you people are lousy bug reporters, or we are doing a descent job at responding. :)
Module rewrite with developers/integrators in mind4.x makes much greater use of Drupal's entity API dropping some of its very specific chaining API. Feel free to take a look at the roadmap ticket for specifics.
New UIWe now have a much nicer UI for creating, editing and sorting sitemaps as well as sitemap types.
API usageIn a nutshell, sitemap variants are now sitemap entities. These are of a sitemap type (sitemap type entity) that is defined by URL generator plugins as well as sitemap generator plugins.
Gbyte blog: Instantiate all classes within a namespace in Symfony and Drupal
Occasionally I find myself needing plugin-like functionality, where users/downstream can throw a class into a folder and expect it to work. My script is supposed to find and instantiate these plugins during runtime without keeping track of their existence.
In a regular Drupal module, one would usually use the plugin architecture, but that comes with its overhead of boilerplate code and may not be the solution for the simplest of use cases.
Many class finder libraries rely on get_declared_classes() which may not be helpful, as the classes in question may not have been declared yet.
If you are on a Drupal 8/9 installation and want to use components already available to you, the Symfony (file) Finder can be an alternative for finding classes in a given namespace.
Installing dependenciesOuside of Drupal 8/9, you may need to require this library in your application:
Gbyte blog: abgeordnetenwatch.de is a winner of the Drupal Splash Awards 2020!
abgeordnetenwatch.de is not your generic community platform - it's a tool that actively creates and enforces communication channels between the people and their political representatives thereby strengthening the democratic process while also being a comprehensive source of information of the political system in Germany.
Because of that and because of the project's high functionality and high efficiency requirements, it is one gbyte is particularly proud to be involved in.
The project has recently won the Drupal Splash Awards 2020 for Germany & Austria in the non-profit category. It is a huge compliment to the small team of developers and to Parlamentwatch e. V. (the organization behind the service), as the Splash awards are regarded as the most prestigious award within the Drupal community.
Award ceremony: Youtube video (with timestamp)
Splash awards entry: Entry description
Drop us a line if you are interested in what makes this awesome project tick.
Gbyte blog: In which order should be Drupal updates and configuration import/export run?
The answer is... generally run updates first. Whether to import or export the configuration afterwards depends on who updated the contrib code base.
You are updating the contrib code baseIf you are updating the contrib code base, run the database updates and then export the configuration, as updates tend to alter the configuration storage data which needs to be commited into the version control system:
Gbyte blog: Skip hooks during a Drupal 8 & 9 migration
When migrating content with the Drupal 8 migrate module, the creation and updating of new entities may fire lots of custom module hooks. This may or may not be desired; if you have found yourself here, it probably interferes with the source data in a problematic way, or unnecessarily slows down the migration process.
The cleanest way I found to stop specific hooks for specific migrations, is to add a dummy/meta field to the migration and check for its value in the hook.
Include a dummy field in the migrationIn the process section of the migration, add a field with a name that will not interfere with any field name of the target entity:
Gbyte blog: Simple XML Sitemap 3.1 released with major new features
This is a technical description of the 3.x branch of the module. For the newer 4.x branch, see this article.
Simple XML sitemap 3.1 has been releasedThe third major version of simple_sitemap has been long in the making bringing a more reliable generation process, a significantly more versatile API and many new functionalities. The first minor ugrade of the 3.x branch comes with views support and human readable sitemaps.
Major new features in 3.1 Views and views arguments supportIncluding view display URLs in the sitemap has been possible through adding these URLs as custom links in the UI (or via the API).
View variations created by view arguments however are tedious to include as one would have to include every version of the URL.
The integration of the simple_sitemap_views inside simple_sitemap 3.x makes it easily doable via the UI.
Thanks to @WalkingDexter for his tremendous work on this submodule!
Human-readable sitemaps with XSL stylesheetsBefore:
Gbyte blog: Why you should be using Simple XML sitemap > 3.0
This is a technical description of the 3.x branch of the module. For the newer 4.x branch, see this article.
Simple XML sitemap 3.0 has been releasedThe third major version of simple_sitemap has been seven months in the making. The module has been rewritten from the ground up and now features a more reliable generation process, a significantly more versatile API and many new functionalities.
Major new features Ability to create any type of sitemap via pluginsThe 8.x-3.x release allows not only to customize the URL generation through URL generator plugins as 2.x did, but also creating custom sitemap types that mix and match a sitemap generator along with several URL generators to create any type of sitemap.
This 3-plugin system coupled with the new concept of sitemap variants makes it possible to run several types of sitemaps on a single Drupal instance. Now e.g a Google news sitemap can coexist with your hreflang sitemap.
A sitemap variant can but does not need to be coupled to entity types/bundles. When creating a sitemap generator, one can define where the content source is located and what to do with it upon sitemap generation/deletion.
Ability to create sitemap variants of various sitemap types via the UIIn 3.x links form a specific entity bundle can be indexed in a specific sitemap variant with its own URL. This means, that apart from /sitemap.xml, there can be e.g
Gbyte blog: Get image URL from media field in twig
Apparently there are still pretty common Drupal 8 theming tasks that cannot be accomplished with the great twig_tweak module. This by the way was me giving a plug to a great little module, which makes half of all your theme preprocess hooks unnecessary.
Update: Apparently there is a module like twig_tweak but with the ability to do the above. It is called bamboo_twig and its documentation can be found here - thanks to Luckhardt Labs for mentioning it. Mind you I have not tested it yet. There is a rather interesting issue in its queue about the lack of collaboration between the two module maintainers.
If you would like to get the URL from an image that is trapped inside of a media entity however, you can either extract it using the aforementioned preprocess function like so:
Gbyte blog: Clone entity data into existing entities in Drupal 8 & 9
Creating a duplicate of an entity is easily done via the entity API method Entity::createDuplicate(). This is a convenient method if the goal is to clone an entity into a new entity, as all identifiers of the previous entity get unset when using this method.
Gbyte blog: Creating Drush 9 commands and porting legacy commands
Drush should be installed and updated through composer. There is no stable Drush 9 version yet, so the development version must be used. Updating to the development version of Drush 9 is a simple as typing:
$ composer require drush/drush:dev-master
Porting your Drush commands to Drush 9Porting the commands is a semi-automatic process: There is a command that will generate the required files and class structure for you. To start the wizard, just type:
$ drush generate drush-command-file -l dev
Drush will ask you for the module's machine name and for the optional path to the legacy Drush command file (the one that has your commands, ending with .drush.inc). You will have to provide the absolute path.
drush.services.ymlThis is the file your Drush command definition goes into. Do not use your module's regular services.yml as you might have done in Drush 8 or else you will confuse the legacy Drush which will lead to a PHP error like this:
Fatal error: Class 'Drush\Commands\DrushCommands' not found in MyModuleCommands.Use the dedicated drush.services.yml file in your module's root directory instead.
The file should look like this:
Gbyte blog: Image indexation and other new features of Simple XML sitemap 2.10
This is a technical description of the 2.x branch of the module. For the newer 3.x branch see this article; for 4.x, see this article.
New features of Simple XML sitemapVersion 2.10 of Simple XML sitemap is mainly a feature release with only a few minor bugs fixed. The new features are
- the implementation of the changefreq parameter
- the ability to set an interval at which to regenerate the sitemap
- the ability to customize XML output
- the ability to add arbitrary links to the sitemap
- image indexation
See the 8.x-2.10 release page for details.
A new version has been released, please make sure to visit the project page.
Simple XML sitemap is now able to create Google image sitemaps through indexing all images attached to entities. This includes images uploaded through the image field as well as inline images uploaded through the WYSIWYG. The inclusion of images can be set at the entity type and bundle level but can be overridden on a per-entity basis giving you all the flexibility.
Gbyte blog: precore.net - a platform for artists and design students
Since its relaunch in 2015, the Drupal 7 powered precore.net has been gaining popularity among artists and design students to become their go-to platform. Until today, design students have uploaded over 700 portfolios providing guidance to enrolling candidates. These portfolios are linked to over 500 art faculties of hundreds of universities.
Before enrolling in a course, a candidate can research their local university and study other students' portfolios or enroll in their local design course to prepare for the entry tests - all of it on precore.net.
On top of that, students provide and collect support on the precore.net forum which boasts over 20000 users who have written nearly 250000 posts. This may be the biggest and most beautiful forum built on top of Drupal core.
The most powerful feature however may be the ability for guests to create most of the site's content without having to go through any type of registration process. Visitors can go ahead and correct their school's information just by clicking 'edit'. Likewise, anyone can write a blog post - no account or personal information needed. We think this technology has massively contributed to the quantity and quality of content on precore.net.
Gbyte blog: Session based content access for anonymous users - Session node access module ported to Drupal 8
Letting users create content without having to register (or going through any other annoying process) is becoming an important customer engagement strategy.
When you allow anonymous users to create content on your website, you want this content to go through a moderation process before it becomes publicly available. To implement this in Drupal, the anonymous user has to be given permission to create content and the content type needs to be unpublished by default.
The problem with Drupal 7 and Drupal 8 is that as soon as the anonymous user saves new content, they loose access rights to it and get redirected to an 'Access denied' page which is not very user friendly.
In addition to the above, you may want the anonymous user to be able to edit or even delete their own content in case they find an error right after submitting it. Users often find typos or other kinds of mistakes right after content submission.
Gbyte created the Session Node Access module to tackle exactly these issues. The module allows administrators to grant certain user roles (not only anonymous users) specific permissions to content they created. These permissions last only as long as the browsing session lasts; after that, the regular permissions apply again. This way it is possible to allow guests or users of a certain role to keep access to their content, even if it is pending for approval.
Now Session Node Access has been ported to Drupal 8 - thank you to Gaël Gosset for doing the initial porting.
Right now this module works only with nodes, we may implement it for other entities in case of demand.
Gbyte blog: Drupal 8 SEO: Differences between simple_sitemap and xmlsitemap
This is a technical comparison of the older 2.x branch of the Simple XML sitemap module and an older development version of XML sitemap. XML sitemap has just had its first release and for more on the newer 4.x branch of Simple XML sitemap see this article.
This comparison may be interesting for XML sitemap users moving to Drupal 8 or for users intending to wait for the port. (Do not wait, help out!) Please also be advised that gbyte made Simple XML sitemap, which makes this comparison intrinsically biased.
There are major differences between Simple XML sitemap (simple_sitemap) and XML sitemap (xmlsitemap) and depending on your use case, you might want to choose one or the other.
What sets the modules apart are their complexity, extensibility, performance and feature sets.
Code baseHaving been built specifically for D8, simple_sitemap has arguably a cleaner code base adhering to D8 standards i (i.e. use of OOP). In contrast, the xmlsitemap module will have a hard time adjusting to D8 technologies and guidelines, as it carries around a whole lot of legacy code going back as far as Drupal 5.
PerformanceWhat is meant here is the impact of the module on a Drupal 8 system, how quick the sitemap generation process is and how long it takes for a visitor to fetch the sitemap.
Sitemap generation performance