(Un)publishing content¶
Deciding if content is visible for user in Publisher is done dynamically - based on user roles.
Note
By default all users can see only published content, but if user have role ROLE_CAN_VIEW_NON_PUBLISHED
then also not published content will be fetched and rendered.
How published content is marked in database?¶
Published content need to match those criteria:
status
property set topublished
publishedAt
property filled with date and timeisPublishable
property set totrue
How to Publish content?¶
By REST API call
1 | curl -X "PATCH" -d "article[status]=published" -H "Content-type:\ application/x-www-form-urlencoded" /api/v1/content/articles/get-involved
|
By code
1 2 3 4 | // $this->container - instance of Service Container
// $article - ArticleInterface implementation
$articleService = $this->container->get('swp.service.article');
$articleService->publish($article);
|
How to check (in code) if content is published?¶
1 2 3 4 5 6 7 | use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
....
$publishWorkflowChecker = $this->serviceContainer->get('swp.publish_workflow.checker');
if ($publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $article)) {
// give access for article
}
|
Note
Content assigned to routes is automatically checked (if it’s publishable for current user) by event listener.
How to Un-publish Content?¶
If an article is published you can easily un-publish it via API as described above. Another way to un-publish already published article is by killing
the article. It can be achieved by setting the value of pubStatus
property to canceled
in the JSON (Ninjs) content according to IPTC standards. Once that status will be set, and the content will be send to Publisher (/content/push API endpoint), article will be un-published immediately and its status will be set to canceled
.