We have a custom module, mymodule, that we are using to create a custom block programmatically. We tried to do the following and it does enable the module successfully, but i get the following warning.

What is the argument that needs to be passed in?

Missing argument 1 for mymodule_update_8501()


function mymodule_install() {
  // Run update on install. 

function mymodule_update_8501(&$sandbox) {
  // Do something.

A hook_update_N implementation is generally supposed to be invoked by the system, not manually.

Instead of thinking of it as "run an update on install", you could think of it as "perform an action on both install and update". A fairly common pattern for that is:

function MYMODULE_install() {

function MYMODULE_update_8501(&$sandbox) {

function _MYMODULE_install_something() {
  // Shared functionality here.

You don't have to use a global function; you could implement the shared functionality in a service and make use of that instead. The point is to separate out the logic for what needs to be done, and consume it in the same way wherever you need to.

If you do want to continue with your current approach, just pass it any initialised variable - doesn't matter what it is if you're not using it, and if your code is the only caller, it won't have any side-effects.

  • we were discussing different scenarios and found that we should most likely use the "perform action on update". In testing, we found that if we ran it in both, the mymodule_update_8501() would fail because we already have a block with that same ID. Your response led to that conclusion and it is marked as such. – usernameabc Jul 31 '18 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.