original_string: public function add($typeSlug)
      {
          $this->loadModel('Content.ContentTypes');
          $this->loadModel('Content.Contents');
          $this->Contents->unbindComments();
          $type = $this->ContentTypes->find()
              ->where(['slug' => $typeSlug])
              ->limit(1)
              ->first();
  
          if (!$type) {
              throw new ContentTypeNotFoundException(__d('content', 'The specified content type ({0}) does not exists.', $type));
          }
  
          if (!$type->userAllowed('create')) {
              throw new ContentCreateException(__d('content', 'You are not allowed to create contents of this type ({0}).', $type->name));
          }
  
          if ($this->request->data()) {
              $data = $this->request->data();
              $data['content_type_slug'] = $type->slug;
              $data['content_type_id'] = $type->id;
              $content = $this->Contents->newEntity($data);
  
              if ($this->Contents->save($content)) {
                  if (!$type->userAllowed('publish')) {
                      $this->Flash->warning(__d('content', 'Content created, but awaiting moderation before publishing it.'));
                  } else {
                      $this->Flash->success(__d('content', 'Content created!.'));
                  }
                  $this->redirect(['plugin' => 'Content', 'controller' => 'manage', 'action' => 'edit', 'prefix' => 'admin', $content->id]);
              } else {
                  $this->Flash->danger(__d('content', 'Something went wrong, please check your information.'));
              }
          } else {
              $content = $this->Contents->newEntity(['content_type_slug' => $type->slug]);
              $content->setDefaults($type);
          }
  
          $content->set('content_type', $type);
          $content = $this->Contents->attachFields($content);
          $languages = LocaleToolbox::languagesList();
          $roles = $this->Contents->Roles->find('list');
  
          $this->title(__d('content', 'Create New Content <small>({0})</small>', $type->slug));
          $this->set(compact('content', 'type', 'languages', 'roles'));
          $this->Breadcrumb
              ->push('/admin/content/manage')
              ->push(__d('content', 'Create new content'), ['plugin' => 'Content', 'controller' => 'manage', 'action' => 'create'])
              ->push($type->name, '');
      }
code: public function add($typeSlug)
      {
          $this->loadModel('Content.ContentTypes');
          $this->loadModel('Content.Contents');
          $this->Contents->unbindComments();
          $type = $this->ContentTypes->find()
              ->where(['slug' => $typeSlug])
              ->limit(1)
              ->first();
  
          if (!$type) {
              throw new ContentTypeNotFoundException(__d('content', 'The specified content type ({0}) does not exists.', $type));
          }
  
          if (!$type->userAllowed('create')) {
              throw new ContentCreateException(__d('content', 'You are not allowed to create contents of this type ({0}).', $type->name));
          }
  
          if ($this->request->data()) {
              $data = $this->request->data();
              $data['content_type_slug'] = $type->slug;
              $data['content_type_id'] = $type->id;
              $content = $this->Contents->newEntity($data);
  
              if ($this->Contents->save($content)) {
                  if (!$type->userAllowed('publish')) {
                      $this->Flash->warning(__d('content', 'Content created, but awaiting moderation before publishing it.'));
                  } else {
                      $this->Flash->success(__d('content', 'Content created!.'));
                  }
                  $this->redirect(['plugin' => 'Content', 'controller' => 'manage', 'action' => 'edit', 'prefix' => 'admin', $content->id]);
              } else {
                  $this->Flash->danger(__d('content', 'Something went wrong, please check your information.'));
              }
          } else {
              $content = $this->Contents->newEntity(['content_type_slug' => $type->slug]);
              $content->setDefaults($type);
          }
  
          $content->set('content_type', $type);
          $content = $this->Contents->attachFields($content);
          $languages = LocaleToolbox::languagesList();
          $roles = $this->Contents->Roles->find('list');
  
          $this->title(__d('content', 'Create New Content <small>({0})</small>', $type->slug));
          $this->set(compact('content', 'type', 'languages', 'roles'));
          $this->Breadcrumb
              ->push('/admin/content/manage')
              ->push(__d('content', 'Create new content'), ['plugin' => 'Content', 'controller' => 'manage', 'action' => 'create'])
              ->push($type->name, '');
      }
code_tokens: public function add ( $ typeSlug ) { $ this -> loadModel ( 'Content.ContentTypes' ) ; $ this -> loadModel ( 'Content.Contents' ) ; $ this -> Contents -> unbindComments ( ) ; $ type = $ this -> ContentTypes -> find ( ) -> where ( [ 'slug' => $ typeSlug ] ) -> limit ( 1 ) -> first ( ) ; if ( ! $ type ) { throw new ContentTypeNotFoundException ( __d ( 'content' , 'The specified content type ({0}) does not exists.' , $ type ) ) ; } if ( ! $ type -> userAllowed ( 'create' ) ) { throw new ContentCreateException ( __d ( 'content' , 'You are not allowed to create contents of this type ({0}).' , $ type -> name ) ) ; } if ( $ this -> request -> data ( ) ) { $ data = $ this -> request -> data ( ) ; $ data [ 'content_type_slug' ] = $ type -> slug ; $ data [ 'content_type_id' ] = $ type -> id ; $ content = $ this -> Contents -> newEntity ( $ data ) ; if ( $ this -> Contents -> save ( $ content ) ) { if ( ! $ type -> userAllowed ( 'publish' ) ) { $ this -> Flash -> warning ( __d ( 'content' , 'Content created, but awaiting moderation before publishing it.' ) ) ; } else { $ this -> Flash -> success ( __d ( 'content' , 'Content created!.' ) ) ; } $ this -> redirect ( [ 'plugin' => 'Content' , 'controller' => 'manage' , 'action' => 'edit' , 'prefix' => 'admin' , $ content -> id ] ) ; } else { $ this -> Flash -> danger ( __d ( 'content' , 'Something went wrong, please check your information.' ) ) ; } } else { $ content = $ this -> Contents -> newEntity ( [ 'content_type_slug' => $ type -> slug ] ) ; $ content -> setDefaults ( $ type ) ; } $ content -> set ( 'content_type' , $ type ) ; $ content = $ this -> Contents -> attachFields ( $ content ) ; $ languages = LocaleToolbox :: languagesList ( ) ; $ roles = $ this -> Contents -> Roles -> find ( 'list' ) ; $ this -> title ( __d ( 'content' , 'Create New Content <small>({0})</small>' , $ type -> slug ) ) ; $ this -> set ( compact ( 'content' , 'type' , 'languages' , 'roles' ) ) ; $ this -> Breadcrumb -> push ( '/admin/content/manage' ) -> push ( __d ( 'content' , 'Create new content' ) , [ 'plugin' => 'Content' , 'controller' => 'manage' , 'action' => 'create' ] ) -> push ( $ type -> name , '' ) ; }
docstring: Shows the "new content" form.
  
  @param string $typeSlug Content type slug. e.g.: "article", "product-info"
  @return void
  @throws \Content\Error\ContentTypeNotFoundException When content type was not
  found
  @throws \Content\Error\ContentCreateException When current user is not allowed
  to create contents of this type
docstring_tokens: Shows the new content form .