public function isAttributeRequired($attribute) { if (in_array($attribute, array('_image'))) { return true; } return parent::isAttributeRequired($attribute); }
/** * @param CActiveRecord $model * @param array $attributes * @return array */ public static function getElements($model, $attributes = []) { $modelAttributes = $model->getAttributes(); $modelElements = []; foreach ($modelAttributes as $attrName => $attrVal) { if (!empty($attributes)) { foreach ($attributes as $attr) { if ($attrName === $attr) { $modelElements[$attr] = ['label' => $model->getAttributeLabel($attr), 'required' => $model->isAttributeRequired($attr), 'type' => 'text']; } } continue; } $modelElements[$attrName] = ['label' => $model->getAttributeLabel($attrName), 'required' => $model->isAttributeRequired($attrName), 'type' => 'text']; // if ($field->inputType == 'dropdownlist') { // $elements['elements']['contextFields']['elements'][$field->inputName . '-' . $field->id]['items'] = // Options::model()->getContextFieldOptions($field->id); // } } return $modelElements; }
/** * Uses HUserInfoForm to check if we have all data, that we need from new user * displays the form to get the required, but not specified user data * * @param CActiveRecord $user user model * @return CActiveRecord user model with correct data */ protected function checkUserData($user) { // trying to fill email and username fields // NOTE: we display `username` field in our form only if it is required by the model if ($this->usernameAttribute && !$user->isAttributeRequired($this->usernameAttribute)) { $this->usernameAttribute = false; } $form = new HUserInfoForm($user, $this->_emailAttribute, $this->usernameAttribute); if (!$form->validateUser()) { // We need to request some info from user $this->controller->render('hoauth.views.form', array('form' => $form)); Yii::app()->end(); } // updating attributes in $user model (if needed) $user = $form->validUserModel; return $user; }
public function isAttributeRequired($attribute) { if (!$this->eavEnable) { return parent::isAttributeRequired($attribute); } if ($this->hasEavAttribute($attribute)) { return $this->isEavAttributeRequired($attribute); } return parent::isAttributeRequired($attribute); }
/** * Checks if a model attribute is required. * * @param CActiveRecord $model Model attribute belongs to * @param string $attribute Name of attribute * @return mixed True if required, else false */ public function isRequired($model, $attribute) { return $model->isAttributeRequired($attribute); }