How to modify the concrete5 core with Composer patches
Sometimes you want to change something in concrete5, but it can't be done easily via a package or with some custom code. What can we do in such a case? Well, of course we don't want to modify the core concrete5 files. Unless...?
Yes, unless there is a proper way to do so of course! I came across a solution watching the concrete5 Github repository where mlocati posted an interesting approach I had not heard of before. Important, you need a Composer based installation of concrete5 for this approach.
How does it work?
Here's how you can apply a patch to the concrete5 core:
- Fork the concrete5 repository, if you haven't yet.
- Commit your changes to the core in your local fork.
- Create a patch file:
If you need a patch from an existing commit, you can use 'git format-patch -1 THE_SHA_HASH'.
- Copy the file to your repository, e.g. to 'patches/your-patch-file.patch'.
- Add this section to your composer.json file:
- Make sure you add cweagans/composer-patches to your Composer dependencies via:
7. Run 'composer install' to apply to patch(es).
When do I need this approach?
It can be handy in case:
- concrete5 hasn't merged your pull request, but you really need the change.
- a certain file or class can't be overridden easily.
- you need a small tweak / customization in the core, but you don't want to maintain a fork, and you don't think concrete5 will merge a pull request with the change.
Make sure you join Slack via https://slack.concrete5.org and ask your question in the #dev channel.