Craft\NeoService::validateFieldSettings PHP Method

validateFieldSettings() public method

Validates a field's settings, loading the settings and block type models with any error messages.
public validateFieldSettings ( Neo_SettingsModel $settings ) : boolean
$settings Neo_SettingsModel
return boolean
    public function validateFieldSettings(Neo_SettingsModel $settings)
    {
        $validates = true;
        $this->_uniqueBlockTypeAndFieldHandles = [];
        $uniqueAttributes = ['name', 'handle'];
        $uniqueAttributeValues = [];
        foreach ($settings->getBlockTypes() as $blockType) {
            if (!$this->validateBlockType($blockType, false)) {
                // Don't break out of the loop because we still want to get validation errors for the remaining block
                // types.
                $validates = false;
            }
            // Do our own unique name/handle validation, since the DB-based validation can't be trusted when saving
            // multiple records at once
            foreach ($uniqueAttributes as $attribute) {
                $value = $blockType->{$attribute};
                if ($value && (!isset($uniqueAttributeValues[$attribute]) || !in_array($value, $uniqueAttributeValues[$attribute]))) {
                    $uniqueAttributeValues[$attribute][] = $value;
                } else {
                    $blockType->addError($attribute, Craft::t('{attribute} "{value}" has already been taken.', ['attribute' => $blockType->getAttributeLabel($attribute), 'value' => HtmlHelper::encode($value)]));
                    $validates = false;
                }
            }
        }
        return $validates;
    }