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.

...

Code Block
languagephp
titlebrowse locations
        // get the location service from the repsitory
        $this->locationService = $repository->getLocationService();
        try
        {
            $location = $this->locationService->loadLocation($locationId);
            $this->browseLocation($location,0,$output);
        }
        catch( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
        {
            // if the location id was not found
            $output->writeln( "No content with id $locationId" );
        }
        catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
        {
            // not allowed to read this location
            $output->writeln( "Anonymous users are not allowed to read location with id $locationId" );
        }

...

Code Block
languagephp
titlehide/unhide location
        // get the location service from the repository
        $locationService = $repository->getLocationService();
        // get the user service from the repsitory
        $userService = $repository->getUserService();
        // load admin user
        $user = $userService->loadUser(14);
        // set current user to admin
        $repository->setCurrentUser($user);
        try
        {
             // load the location info from the given location id
            $location = $contentService->loadContentInfo($contentId);
            // hide the location
            $hiddenLocation = $locationService->hideLocation($location);
            // print out the location
            print_r($hiddenLocation);
            // unhide the location
            $unhiddenLocation = $locationService->unhideLocation($hiddenLocation);
            // print out the location
            print_r($unhiddenLocation);
        }
        catch(\eZ\Publish\API\Repository\Exceptions\NotFoundException $e)
        {
            // react on content or location not found
            $output->writeln($e->getMessage());
        }
        catch(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e)
        {
            // react on permission denied
            $output->writeln($e->getMessage());
        }