public function onBeforeWrite()
    {
        $return = parent::onBeforeWrite();

        // Field name must be unique
        $exists = self::get()->filter('Name', $this->Name)->exclude('ID', $this->ID);
        if ($exists->count()) {
            throw new ValidationException(
                _t('Moo_EditableField.UNIQUENAME', 'Field name "{name}" must be unique', '',
                    ['name' => $this->Name])
            );
        }

        // Filter field name from un-supported HTML attribute value
        $this->Name = preg_replace('/[^a-zA-Z0-9_]+/', '', $this->Name);

        // Get custom settings from the current object of request POST
        $customSettings = $this->getSettings();
        if (empty($customSettings)) {
            $customSettings = (array) Controller::curr()->getRequest()->postVar('CustomSettings');
        }

        // Filter out any un-supported settings by the subclasss
        if (!empty($this->customSettingsFields)) {
            $customSettings = array_intersect_key($customSettings, array_flip((array) $this->customSettingsFields));
        }

        // Set the filtered settings
        $this->setSettings($customSettings);

        return $return;
    }