Plesk SDK API allows you to extend Plesk forms with your own content. The hook enables embedding controls from an extension into any Plesk form, for example:

  • The “Git deploy section” on the domain creation screen.
  • Ruby / Python applications on the domain creation screen.
  • The “Social Accounts” link in the profile.
  • Two-factor authentication in profile.

The hook is designed to append sub forms from all extensions during the rendering of the form. Instances of pm_Form_SubForm can be used, but it is not required.

Note: Only Zend forms (those with URL starting with /smb/ and /admin/) are supported.

The life cycle of every Plesk form consists of 3 stages:

  • init: add elements with initial values.
  • isValid: check validators on each element, an overriden method could prevent or extend validation.
  • process: perform actions, save new values, etc.

Each stage will cause the execution of the corresponding method in the sub form. To define which form should be handled by the hook, arguments are passed in the hook: $controller, $action, and $formId.

Examples

The hook should be implemented in plib/hooks/Form.php

class Modules_Git_Form extends pm_Hook_Form
{
    public function getSubForms($controller, $action, $formId)
    {
        if (in_array($formId, [static::FORM_CREATE_SUBSCRIPTION, static::FORM_CREATE_CUSTOMER])) {
            $subForm = new AddWithDomain(['context' => [
                'isSubscriptionCreation' => true,
            ], 'moveBefore' => 'subscription-subscriptionInfo']);
        } elseif (in_array($formId, [static::FORM_CREATE_DOMAIN, static::FORM_CREATE_SUBDOMAIN])) {
            $subForm = new AddWithDomain(['context' => [
                'isDomain' => static::FORM_CREATE_DOMAIN === $formId,
                'isSubscriptionCreation' => false,
            ], 'moveAfter' => 'hostingSettings']);
        } else {
            return [];
        }
        return ['git' => $subForm];
    }
}