original_string: public function add()
      {
          $this->loadModel('User.Users');
          $user = $this->Users->newEntity();
          $user = $this->Users->attachFields($user);
          $languages = LocaleToolbox::languagesList();
          $roles = $this->Users->Roles->find('list', [
              'conditions' => [
                  'id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]
              ]
          ]);
  
          if ($this->request->data()) {
              $user->accessible('id', false);
              $data = $this->request->data;
  
              if (isset($data['welcome_message'])) {
                  $sendWelcomeMessage = (bool)$data['welcome_message'];
                  unset($data['welcome_message']);
              } else {
                  $sendWelcomeMessage = false;
              }
  
              $user = $this->Users->patchEntity($user, $data);
              if ($this->Users->save($user)) {
                  if ($sendWelcomeMessage) {
                      NotificationManager::welcome($user)->send();
                  }
  
                  $this->Flash->success(__d('user', 'User successfully registered!'));
                  $this->redirect(['plugin' => 'User', 'controller' => 'manage', 'action' => 'edit', $user->id]);
              } else {
                  $this->Flash->danger(__d('user', 'User could not be registered, please check your information.'));
              }
          }
  
          $this->title(__d('user', 'Register New User'));
          $this->set(compact('user', 'roles', 'languages'));
          $this->Breadcrumb->push('/admin/user/manage');
      }
code: public function add()
      {
          $this->loadModel('User.Users');
          $user = $this->Users->newEntity();
          $user = $this->Users->attachFields($user);
          $languages = LocaleToolbox::languagesList();
          $roles = $this->Users->Roles->find('list', [
              'conditions' => [
                  'id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]
              ]
          ]);
  
          if ($this->request->data()) {
              $user->accessible('id', false);
              $data = $this->request->data;
  
              if (isset($data['welcome_message'])) {
                  $sendWelcomeMessage = (bool)$data['welcome_message'];
                  unset($data['welcome_message']);
              } else {
                  $sendWelcomeMessage = false;
              }
  
              $user = $this->Users->patchEntity($user, $data);
              if ($this->Users->save($user)) {
                  if ($sendWelcomeMessage) {
                      NotificationManager::welcome($user)->send();
                  }
  
                  $this->Flash->success(__d('user', 'User successfully registered!'));
                  $this->redirect(['plugin' => 'User', 'controller' => 'manage', 'action' => 'edit', $user->id]);
              } else {
                  $this->Flash->danger(__d('user', 'User could not be registered, please check your information.'));
              }
          }
  
          $this->title(__d('user', 'Register New User'));
          $this->set(compact('user', 'roles', 'languages'));
          $this->Breadcrumb->push('/admin/user/manage');
      }
code_tokens: public function add ( ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> newEntity ( ) ; $ user = $ this -> Users -> attachFields ( $ user ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Users -> Roles -> find ( 'list' , [ 'conditions' => [ 'id NOT IN' => [ ROLE_ID_AUTHENTICATED , ROLE_ID_ANONYMOUS ] ] ] ) ; if ( $ this -> request -> data ( ) ) { $ user -> accessible ( 'id' , false ) ; $ data = $ this -> request -> data ; if ( isset ( $ data [ 'welcome_message' ] ) ) { $ sendWelcomeMessage = ( bool ) $ data [ 'welcome_message' ] ; unset ( $ data [ 'welcome_message' ] ) ; } else { $ sendWelcomeMessage = false ; } $ user = $ this -> Users -> patchEntity ( $ user , $ data ) ; if ( $ this -> Users -> save ( $ user ) ) { if ( $ sendWelcomeMessage ) { NotificationManager :: welcome ( $ user ) -> send ( ) ; } $ this -> Flash -> success ( __d ( 'user' , 'User successfully registered!' ) ) ; $ this -> redirect ( [ 'plugin' => 'User' , 'controller' => 'manage' , 'action' => 'edit' , $ user -> id ] ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be registered, please check your information.' ) ) ; } } $ this -> title ( __d ( 'user' , 'Register New User' ) ) ; $ this -> set ( compact ( 'user' , 'roles' , 'languages' ) ) ; $ this -> Breadcrumb -> push ( '/admin/user/manage' ) ; }
docstring: Adds a new user.
  
  @return void
docstring_tokens: Adds a new user .