Esempio n. 1
0
 protected function getSettingsModel()
 {
     $settings = new Neo_SettingsModel($this->model);
     $settings->setField($this->model);
     return $settings;
 }
Esempio n. 2
0
 /**
  * Validates a field's settings, loading the settings and block type models with any error messages.
  *
  * @param Neo_SettingsModel $settings
  * @return bool
  */
 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;
 }