Hello,
I would like to ask about modifying the source code of certain Open edX functionalities. At the moment, I’m making these changes in my own fork on GitHub, but I’m concerned that I’ll run into problems when updating to newer Open edX versions in the future.
Is there a way to make such changes similar to how we apply a theme via ~/.local/share/tutor/env/build/openedx/themes?
Or is it necessary to constantly track changes on GitHub and manually adapt each time?
Yes, I think a better way to handle this is by creating an Open edX plugin to override the functionality you need. Instead of modifying the core code directly, plugins let you extend or customize things in a cleaner and more maintainable way.
@abylaikhan.suev.02 The Options for Extending the edX Platform page could be useful - it contains an overview of the mechanisms that could be used to extend the platform and links to more detailed documentation for each of them. Deciding which mechanism to use depends on what you’re trying to change/add/extend. If you could post more details about what customization you’re trying to do, we could try to point you in the right direction.
@abylaikhan.suev.02 Thank you for providing an example. Looking at this code, I have the following assumptions:
You want to overwrite this function to add custom fields for filtering courses which are not present in the default UI.
You’ve updated the templates for that UI to include new filters via a theme.
And I also have a question:
By overwriting fully overwriting the default function, you’re discarding some of the default functionality, e.g. your code doesn’t check if a user has access to the course (at least not the same way the default implementation does) and also removes some of the settings. Are you ok with that?
Either way, here is how I would approach this. What you’re trying to do is not trivial, in the sense that there is mechanism that would allow you to change this easily and/or directly. You can in theory create an upstream PR where you add the pluggable_override to this function or a filter, which would allow you and others to easily change/affect this code. However, there are ways to do what you want without that.
The implementation details will depend on your answer to the question above (i.e. do you want to discard the default implementation or not?). In both cases you can achieve what you want via a plugin - link to how to get started.
If you’re ok with discarding the default implementation and want a completely custom view, I think you can achieve this by creating a custom middleware in the plugin that you created (you would need to add lines of configuration that would install your plugin and then append your custom middleware to the list of middlewares). In the middleware you would check each request - if the URL of the request matches the pattern you want - if it matches, then you process it with custom logic, otherwise you let the requests continue on. You might have to figure out how to implement the middleware for your usecase yourself, but I think in this case you could use process_view hook to process the requests that you want with a custom view function (which you also would define in the plugin).
Does Tutor perhaps have the ability to build from an alternative edx-platform repo? If all of the other options fail, maintaining a (close) fork would seem to be a possible fallback.
I think it does, at least for dev. I don’t use tutor directly for deployments, so I don’t know if it works there, but I would think that it does, since it would just use the built image to deploy.
In Grove (which is a tool that we use that is like an abstraction around tutor) we are able to specify alternative repo and branch/tag (e.g. where EDX_PLATFORM_VERSION is used), but I never looked into how it interacts with tutor to make it work.
Is there an example of overriding a function using plugins?
I’ve only come across adding new functions via plugins.
Sorry, but my level is clearly lower, and I’m trying to do everything myself.