Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

php app/console cookbook:run  57

 

Receipt 2  Creating

...

How to create content type groups, content types and content.

 

 

a content type group

This snippet creates a content type group for a given identifier

 

Code Block
languagephp
titlecreate content type group
linenumberstrue
        $contentTypeService = $repository->getContentTypeService();
        try
        {
            // instanciate a create struct
            $groupCreate = $this->contentTypeService->newContentTypeGroupCreateStruct($groupIdentifier);
            // call service method
            $contentTypeGroup =  $this->contentTypeService->createContentTypeGroup( $groupCreate );
            // print out the group
            print_r($contentTypeGroup);
        }
        catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
        {
            // react on permission denied
            $output->writeln($e->getMessage());
        }
        catch( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e )
        {
            // react on identifier already exists
            $output->writeln($e->getMessage());
        }

If this snipped is run with the same init code from receipt 1 we will get an UnauthorizedException.

The solution is described in the next receipt.

Receipt 3 - Setting the user for authorizing actions

By default the repository assumes the anonymous user is acting. To change this the following code can be executed

Code Block
languagephp
titleauthentication
        // get the user service from the repository
		$userService = $repository->getUserService();
        // load user by credentials
        $user = $userService->loadUserByCredentials($user,$password);
        // set user in repository
        $repository->setCurrentUser($user);

If the user is identified by other mechanisms the user also can be loaded by its id.