/**
  * Override base init function to add event handler that will handle auth clients during configuration editing
  */
 public function init()
 {
     parent::init();
     $this->on(self::configurationSaveEvent(), function ($event) {
         /** @var ConfigConfigurationModel $model */
         $model = $event->configurableModel;
         if (YII_CONSOLE === true) {
             return;
         }
         if (intval(Yii::$app->request->post('addAuthClientFlag', 0)) === 1 && isset($_POST['AuthClientConfig'][-1]['class_name']) === true) {
             // new auth client added
             $class_name = $_POST['AuthClientConfig'][-1]['class_name'];
             $validator = new ClassnameValidator();
             // Hey, there's no error here - validator should return null if there's no errors
             if ($validator->validateValue($class_name) === null) {
                 $new = new AuthClientConfig();
                 $new->class_name = $class_name;
                 $new->determineType();
                 $model->authClients[] = $new;
             } else {
                 Yii::$app->session->addFlash('error', Yii::t('app', 'The class you wanted to add as auth client doesn\'t exist.'));
             }
         }
         if (intval(Yii::$app->request->post('removeAuthClientIndex', -1)) >= 0) {
             $indexToRemove = intval(Yii::$app->request->post('removeAuthClientIndex', -1));
             if (isset($model->authClients[$indexToRemove]) === true) {
                 unset($model->authClients[$indexToRemove]);
                 Yii::$app->session->addFlash('info', Yii::t('app', 'Auth client was deleted.'));
             } else {
                 Yii::$app->session->addFlash('error', Yii::t('app', 'Bad auth client index specified.'));
             }
         }
         $authClientsData = Yii::$app->request->post('AuthClientConfig');
         $isValid = true;
         if (is_array($authClientsData) === true) {
             foreach ($authClientsData as $index => $data) {
                 if (isset($model->authClients[$index]) === true) {
                     $model->authClients[$index]->setAttributes($data);
                     $model->authClients[$index]->determineType();
                     if ($model->authClients[$index]->validate() === false) {
                         $isValid = false;
                     }
                 }
             }
         }
         if ($isValid === false) {
             Yii::$app->session->addFlash('warning', Yii::t('app', 'Please fill in all required information for auth client configuration.'));
         }
     });
 }