Overriding Varbase
First Rule in Overriding
Do not change the original code of Drupal Core, Varbase, Vartheme or any other Varbase components. In another words "Do not hack the original code without a trace for the change"
Use the standard Drupal overriding methods.
Custom Tweak Modules
Create custom modules and have your override in them.
Basic hooks like hook alter.
Use Event Subscribers and dispatches.
Switching a Class for a service with a custom or extended Class.
Patching Bugs
In case of capturing a bug. Search if it was filed in an issue. Look if the a patch fix for the issue was uploaded.
Apply the patch using the Composer patching method using:
Do not use the manual patching method in projects.
This action will guarantee the direction of keeping track of changes over the code.
Example: In the composer.json
file for the project:
Please add the "Issue Number" and the URL for the used patch
Patch for a New Enhancements
An introductory patch for an enhancement over a Varbase component or any Drupal project is welcomed.
A patch may not be committed on the spot. It will need review, and testing for what affect it may do for websites.
A patch will work. But although a custom module is the better logic.
Ignoring Patches
Using the cweagans/composer-patches composer plugin with patches-ignore
There may be situations in which you want to ignore a patch supplied by a dependency. For example:
You use a different more recent version of a dependency, and now a patch isn't applying.
You have a more up to date patch than the dependency, and want to use yours instead of theirs.
A dependency's patch adds a feature to a project that you don't need.
Your patches conflict with a dependency's patches.
Example:
The Varbase Core module is requiring Drupal Core with "drupal/core": "~9.0",
. Having number of patches to fix issues or overriding Drupal core.
Varbase Core's composer.json
file for the 9.0.7 version
https://github.com/Vardot/varbase_core/blob/9.0.7/composer.json#L138
Let imagine that the Drupal core release team had a new release, But they had committed the following issue:
Issue #3165435: Fix tour route as route name when a selected node had been set as the front
The patch fix for the core issue was added when a fix was needed for the following issue:
Issue #3164237: Fix Varbase Welcome message not showing up after install compilation after adding and enabling moderation sidebar on the homepage
At the point of a new release for Drupal core and in case the patch was committed.
The cweagans/compsoer-patches composer plugin will not allow to apply it if it was committed.
Ignore the patch being used as in the following example method:
Recommended Patching Method with Gitlab Issue Forks
If you use the URL to the Gitlab MR directly, your code base will change without warning, as people work on the merge request.
Recommended to use the local patch method in this case.
Download the
.diff
or.patch
file in apatches
folder in the project.Add the module name, issue number, and date for the MR changes to the name of the file.
Add the patch local patch to patches.
Example ( NOT Recommended ):
Example ( Recommended remote patch file ):
Example ( Recommended local patch/diff file ):
WARNING: The URL for a Merge Request patch file will be named after the MR and will not change as more and more commits are being added to the MR. The contents of the patch file will change, however.
This effectively means that you will get the latest version of the code from an issue, but you can't lock the patch file to a previous state, ignoring newer commits, until this issue is fixed. So, it brings a security risk because any new commit to the issue's branch will be automatically deployed to your repo via the next "composer install" launch and can harm your project!
Therefore, it's strongly recommended to lock the patch file versions on production sites. To do so you must download the patch file and use it in composer from a local directory, or upload it to the same issue as a file. If you use the URL to the Gitlab MR directly, your codebase will change without warning, as people work on the merge request.
Do not keep patches or patches-ignore for long in projects.
Keep track of them, and clean not needed patches.
Report back if you'd spotted and committed patch. So it will be removed from the module.
Report back if you'd spotted a better patch logic and standard. So it will be used instead of the old patch.
Last updated