Plesk SDK API allows you to embed custom data into lists of Plesk objects (such as domains, service plans, and so on).

Note: This API works only for Zend pages (pages whose URLs contain /admin or /smb)

To embed in lists that already exist in the Plesk GUI implement the pm_Hook_SimpleList abstract class. It provides the following methods:

  • isEnabled($controller, $action, $activeList) - defines which list will be handled by the hook.

  • getDataProvider($controller, $action, $activeList, $data) - extends or overrides the original data provider. A data provider can be an array or an instance of Zend_Db_Select.

    Note: You cannot change the type of $data from array to Zend_Db_Select and vice versa. This method is primarily used to add and/or delete rows in the dataset.

  • getData($controller, $action, $activeList, $data) - extends or overrides the original data set before it is send to the client. This method is mainly used for small changes like filtering and sorting data on the current page.

    We strongly recommend you to use a prefix (for example, ext<YourExtensionId>) for naming new fields.

  • getColumns($controller, $action, $activeList) - describes the columns that will be added to the list.

    Columns are defined similarly to the pm_View_List_Simple::setColumns() method.

    By default, the new column will be added at the end. To determine the position of the new column you can set the insertBefore or insertAfter parameters in the column definition. These parameters can take the following values:

    • A positive integer - column number from the start.
    • A negative integer - column number from end.
    • A string - a dataIndex property of an existing column.
  • getColumnsOverride($controller, $action, $activeList) - describes the way some of the existing columns will be changed.

Examples

Define which list should be handled by the hook

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    public function isEnabled($controller, $action, $activeList)
    {
        // Modify only domains lists
        return $controller === 'domain' && $action === 'list'
            || $controller === 'customer' && $action === 'domains'
            || $controller === 'reseller' && $action === 'domains';
    }
}

image 77249

Hide all domains owned by Ganesh Kamala

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    public function getDataProvider($controller, $action, $activeList, $data)
    {
        // Hide all domains for client with id 5
        $data->where('c.id <> ?', 5);

        return $data;
    }
}

image 77250

Increase the values in the ‘Disk Usage’ column

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    public function getData($controller, $action, $activeList, $data)
    {
        foreach ($data as &$row) {
             $row['realSize'] += 1048576;
        }

        return $data;
    }
}

image 77251

Change the title of the “Subscriber” column to “Owner”

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    ...
    public function getColumnsOverride($controller, $action, $activeList)
    {
        return [
            'ownerName' => [
                'title' => 'Owner',
            ],
        ];
    }
    ...
}

image 77252

Hide the ‘Setup Date’ column

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    ...
    public function getColumnsOverride($controller, $action, $activeList)
    {
        return [
            'setupDate' => [
               'isVisible' => false,
            ],
        ];
    }
    ...
}

image 77253

Add a column named ‘Random’ containing random numbers from 0 to 100 in the fourth rightmost position

src/plib/hooks/SimpleList.php

<?php
class Modules_<YourExtensionName>_SimpleList extends pm_Hook_SimpleList
{
    ...
    public function getData($controller, $action, $activeList, $data)
    {
         foreach ($data as &$row) {
             $row['extHookSimplelistRand'] = rand(0, 100);
        }

        return $data;
    }
    public function getColumns($controller, $action, $activeList)
    {
        return [
            'extHookSimplelistRand' => [
                'title' => 'Random',
                'insertBefore' => -3,
            ],
        ];
    }
    ...
}

image 77255

A sample extension illustrating the concept can be found here.