public static function create_default_elements(SiteTree $record): int
    {
        $count = 0;
        if (!$record || !$record->ID)
        {
            throw new SS_HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
        }

        if ($relationNames = ElementsExtension::page_element_relation_names($record))
        {
            $defaultElements = $record->getDefaultElements();
            if (count($relationNames) > 0)
            {
                foreach ($relationNames as $relationName => $elementsClasses)
                {
                    if (isset($defaultElements[$relationName]))
                    {
                        $elementClasses = $defaultElements[$relationName];
                        foreach ($elementClasses as $className)
                        {
                            $definedElements = $record->ElementsByRelation($relationName)->map('ClassName', 'ClassName');
                            if (!isset($definedElements[$className]))
                            {
                                $element = new $className;
                                $element->populate('PageID', $record->ID, $relationName);
                                $element->write();
                                $count++;
                            }
                        }
                    }
                }
            }
        }
        return $count;
    }