I am trying to use hook_provision_provision_apache_vhost_config() to write more server variables to my apache/nginx configs.

The problem is that I don't have access to all of the available information in the site context.

I have fixed this by adding $this to the hook invocation.

So now, Provision/Config/Apache/Site.php looks like this:


/** 
 * Apache site level config class. Virtual host.
 */
class Provision_Config_Apache_Site extends Provision_Config_Http_Site {
  function process() {
    parent::process();
    $this->data['extra_config'] = "# Extra configuration from modules:\n";
    $this->data['extra_config'] .= join("\n", drush_command_invoke_all('provision_apache_vhost_config', $this->uri, $this->data, $this));
  }
}

We could remove the $this->uri and $this->data, but this would break backwards compatibility with any existing hook implementations.

This is a problem for a lot of hooks actually...

  • hook_provision_drupal_config
  • drush_hook_provision_apache_server_config
  • drush_hook_provision_apache_dir_config
  • drush_hook_provision_apache_vhost_config
  • drush_hook_provision_nginx_server_config
  • drush_hook_provision_nginx_dir_config
  • drush_hook_provision_nginx_vhost_config

I propose that in the current release branch we add $this as an additional parameter to all of the hook invocations so we don't break backwards compatibiltiy, and we revisit this in future releases.

I am going to push a branch soon with these proposed changes.

Thoughts?

Thanks!

Comments

Jon Pugh created an issue. See original summary.

Jon Pugh’s picture

Status: Active » Needs review

New code available in branches 6.x-2.x-provision-hooks-2562467 and 7.x-3.x-provision-hooks-2562467

Status: Needs review » Active
  • Jon Pugh committed 017af75 on 6.x-2.x-provision-hooks-2562467
    Issue #2562467: Add full context object to provision config hooks.
    
Jon Pugh’s picture

Status: Active » Needs review

Ok, I am now realizing that the d() function is available inside these hooks, but it's not documented.

Not sure what the best approach here is.

Do we:

  1. Pass $this as a parameter to the hooks like I did in the branches? or...
  2. Document the availability of d() function and recommend that be used? If d() is available, why not just remove the parameters from the hook calls altogether?
ergonlogic’s picture

Component: Code » Documentation
Category: Bug report » Task
Status: Needs review » Needs work

d() is pretty much always available, but carries an awful lot of complex data around with it. The $uri and $data parameters simplify access to the most common data we're likely to use within these hooks. This is similar to how $form_id is provided in hook_form_alter(), despite the fact that it could be pulled out of $form.

Feel free to add an example of d() within the API docs for these hooks. Otherwise, I think this could be Closed (works as designed).

  • Jon Pugh committed f36d2c5 on 6.x-2.x
    Issue #2562467: Adding mention of d() to the documentation blocks for...
  • Jon Pugh committed 83d3a51 on 7.x-3.x
    Issue #2562467: Adding mention of d() to the documentation blocks for...
Jon Pugh’s picture

Status: Needs work » Fixed

Good call. I've added the mention to the doc blocks and deleted the branches I created.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gboudrias’s picture

Issue tags: +Aegir 3.2