function getSearchFields() { if ($this->fields && $this->fields->count()) { return $this->fields; } $fields = new FieldList(TextField::create('Name'), TextField::create('Email'), TextField::create('Company'), CheckboxSetField::create('Status')->setSource(CustomerStatus::get()->map()->toArray()), CheckboxSetField::create('Tags')->setSource(CustomerTag::get()->map()->toArray())); $locales = PostmarkHelper::MemberLocales(); if ($locales && count($locales)) { $locale = DropdownField::create('Locale')->setSource($locales)->setEmptyString('Select language'); $fields->insertBefore($locale, 'Name'); } $this->extend('updateCustomerSearchFields', $fields); $this->fields = $fields; return $this->fields; }
protected function validate() { parent::validate(); if (!$this->ID) { $exists = CustomerTag::get()->filter('Title', $this->Title)->Count(); if ($exists == 1) { $message = 'A tag by this name already exists'; return new ValidationResult(false, $message); } else { if ($exists == 0) { $message = 'A new tag "' . $this->Title . '" has been added'; return new ValidationResult(true, $message); } } } else { if ($this->Title == "") { $message = 'A tag must not be empty'; return new ValidationResult(false, $message); } return parent::validate(); } }