Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (56 sloc) 2.66 KB
<?php
namespace DP\TestCommandsBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CreateRichTextEntitiesCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName( 'dp:createrichtextentities' )
->setDescription( 'Create RichText with HTML entities' );
}
protected function execute( InputInterface $input, OutputInterface $output )
{
$repository = $this->getContainer()->get( 'ezpublish.api.repository' );
$contentService = $repository->getContentService();
$locationService = $repository->getLocationService();
$contentTypeService = $repository->getContentTypeService();
$repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
// fetch the input arguments
$parentLocationId = 2;
$contentTypeIdentifier = 'richtextest';
$name = "Non break space or other HTML entities";
$summary = '<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit"><p>Quote &quot;</p><p>Non break space &nbsp;</p></section>';
try
{
$contentType = $contentTypeService->loadContentTypeByIdentifier( $contentTypeIdentifier );
$contentCreateStruct = $contentService->newContentCreateStruct( $contentType, 'eng-GB' );
$contentCreateStruct->setField( 'name', $name );
$contentCreateStruct->setField( 'summary', $summary );
// instantiate a location create struct from the parent location
$locationCreateStruct = $locationService->newLocationCreateStruct( $parentLocationId );
// create a draft using the content and location create struct and publish it
$draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) );
$content = $contentService->publishVersion( $draft->versionInfo );
// print out the content
print_r( $content );
}
// Content type or location not found
catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
{
$output->writeln( $e->getMessage() );
}
// Invalid field value
catch ( \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e )
{
$output->writeln( $e->getMessage() );
}
// Required field missing or empty
catch ( \eZ\Publish\API\Repository\Exceptions\ContentValidationException $e )
{
$output->writeln( $e->getMessage() );
}
}
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.