Documentation

PrepareSettings

string
CIBlockProperty*::PrepareSettings(
array arFields
);

The method returns an array with additional property settings, or a complete set of settings, including standard settings. Method is static when using standard properties. Must be static for properties, created by client when using php7.

Note №1: before Information block module version 12.5.7 the method returns only an array with additional property settings.

Note №2: is called before saving property metadata into the database.

Call parameters

Parameter Description
arFields
Metadata fields property values. See Structure for Iblock Module Tables

Returned value

String or an array. When method returns a complete set of settings, additional settings are passed in the USER_TYPE_SETTINGS key as an array.

See Also

Examples

Without modifying main property fields

class CIBlockPropertyMyDateTime
{
    public static function PrepareSettings($arFields): array
    {
        $fields = [];
        if (isset($arFields['USER_TYPE_SETTINGS']) && is_array($arFields['USER_TYPE_SETTINGS']))
        {
            $fields = $arFields['USER_TYPE_SETTINGS'];
        }

        $width = (int)($fields['WIDTH'] ?? 0);
        if ($width <= 0)
        {
            $width = 100;
        }
        $height = (int)($fields['HEIGHT'] ?? 0);
        if ($height <= 0)
        {
            $height = 100;
        }
        
        return [
            'WIDTH' => $width,
            'HEIGHT' => $height
        ];
    }
}

With modified main fields:

class CIBlockPropertyMyDate
{
    public static function PrepareSettings($fields): array
    {
        $userSettings = [];
        if (isset($fields['USER_TYPE_SETTINGS']) && is_array($fields['USER_TYPE_SETTINGS']))
        {
            $userSettings = $fields['USER_TYPE_SETTINGS'];
        }

        $userSettings['WIDTH'] = (int)($userSettings['WIDTH'] ?? 0);
        if ($userSettings['WIDTH'] <= 0)
        {
            $userSettings['WIDTH'] = 100;
        }
        $userSettings['HEIGHT'] = (int)($userSettings['HEIGHT'] ?? 0);
        if ($userSettings['HEIGHT'] <= 0)
        {
            $userSettings['HEIGHT'] = 100;
        }

        $fields['MULTIPLE'] = 'N'; // restrict property multiplicity
        $fields['USER_TYPE_SETTINGS'] = $userSettings;

        return $fields;
    }
}

© «Bitrix24», 2001-2024
Up