/** * Validates a Matrix field's settings. * * If the settings don’t validate, any validation errors will be stored on the settings model. * * @param MatrixSettingsModel $settings The settings model. * * @return bool Whether the settings validated. */ public function validateFieldSettings(MatrixSettingsModel $settings) { $validates = true; $this->_uniqueBlockTypeAndFieldHandles = array(); $uniqueAttributes = array('name', 'handle'); $uniqueAttributeValues = array(); 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.', array('attribute' => $blockType->getAttributeLabel($attribute), 'value' => HtmlHelper::encode($value)))); $validates = false; } } } return $validates; }
/** * Validates a Matrix field's settings. * * If the settings don’t validate, any validation errors will be stored on the settings model. * * @param MatrixSettingsModel $settings The settings model. * * @return bool Whether the settings validated. */ public function validateFieldSettings(MatrixSettingsModel $settings) { $validates = true; $this->_uniqueBlockTypeAndFieldHandles = array(); foreach ($settings->getBlockTypes() as $blockType) { if (!$this->validateBlockType($blockType)) { // Don't break out of the loop because we still want to get validation errors for the remaining block // types. $validates = false; } } return $validates; }