Documentation

Page extends AbstractBaseApi
in package

Canvas LMS Pages API

Provides functionality to manage course content pages in Canvas LMS. Pages are fundamental Canvas content elements that allow instructors to create and organize course materials, syllabi, instructions, and other content.

Usage Examples:

// Set course context (required for all operations)
$course = Course::find(123);
Page::setCourse($course);

// Create a new page
$pageData = [
    'title' => 'Course Syllabus',
    'body' => '<h1>Welcome to the course</h1><p>Course content...</p>',
    'published' => true,
    'editing_roles' => 'teachers'
];
$page = Page::create($pageData);

// Find a page by URL slug
$page = Page::findByUrl('course-syllabus');

// List all pages for the course
$pages = Page::get();

// Get only published pages
$publishedPages = Page::get(['published' => true]);

// Get the course front page
$frontPage = Page::fetchFrontPage();

// Update a page
$updatedPage = Page::update('course-syllabus', ['body' => 'Updated content']);

// Update using instance method
$page = Page::findByUrl('course-syllabus');
$page->setBody('New content');
$success = $page->save();

// Set a page as the front page
$page->makeFrontPage();

// Publish/unpublish a page
$page->publish();
$page->unpublish();

// Delete a page
$page = Page::findByUrl('old-content');
$success = $page->delete();

Table of Contents

Constants

EDITING_ROLES  = ['teachers' => 'teachers', 'students' => 'students', 'members' => 'members', 'public' => 'public']
Page editing roles constants

Properties

$blockEditorAttributes  : array<string, mixed>|null
Block editor attributes (when editor is 'block_editor')
$body  : string|null
Page body content (HTML)
$createdAt  : string|null
Page creation timestamp
$editingRoles  : string|null
Who can edit the page
$editor  : string|null
The editor used to create/edit the page ('rce' or 'block_editor')
$frontPage  : bool|null
Whether this is the course front page
$htmlUrl  : string|null
Full Canvas URL to the page
$lastEditedBy  : array<string, mixed>|null
User who last edited the page
$lockedForUser  : bool|null
Whether page is locked for the current user
$lockExplanation  : string|null
Lock explanation if page is locked
$lockInfo  : string|null
Lock information if page is locked
$pageId  : int|null
Page numeric ID
$pageViewsCount  : int|null
Number of page views
$publishAt  : string|null
Scheduled publication date
$published  : bool|null
Whether page is published
$revisionId  : int|null
Page revision ID
$title  : string|null
Page title
$updatedAt  : string|null
Page last update timestamp
$url  : string|null
Page URL slug (used as identifier)
$workflowState  : string|null
Page workflow state
$apiClient  : HttpClientInterface
$course  : Course|null
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Create a new Page instance
all()  : array<string|int, static>
Get all pages of results
checkCourse()  : bool
Check if course context is set
course()  : Course|null
Get the course this page belongs to
create()  : self
Create a new page
delete()  : self
Delete the page
duplicate()  : self
Duplicate this page
fetchFrontPage()  : self|null
Get the course front page
find()  : self
Find a single page by ID
findByUrl()  : self
Find a single page by URL slug
generateSlug()  : string
Generate a URL slug from a title
get()  : array<string|int, Page>
Fetch all pages for the course
getBlockEditorAttributes()  : array<string, mixed>|null
Get block editor attributes
getBody()  : string|null
Get page body content
getCreatedAt()  : string|null
Get created at timestamp
getEditingRoles()  : string|null
Get editing roles
getEditor()  : string|null
Get editor type
getFrontPage()  : bool|null
Get front page status
getHtmlUrl()  : string|null
Get HTML URL
getLastEditedBy()  : array<string, mixed>|null
Get last edited by user
getLockedForUser()  : bool|null
Get locked for user status
getLockExplanation()  : string|null
Get lock explanation
getLockInfo()  : string|null
Get lock info
getPageId()  : int|null
Get page ID
getPageViewsCount()  : int|null
Get page views count
getPublishAt()  : string|null
Get publish at date
getPublished()  : bool|null
Get published status
getRevisionId()  : int|null
Get revision ID
getSafeBody()  : string|null
Get sanitized body content safe for display
getTitle()  : string|null
Get page title
getUpdatedAt()  : string|null
Get updated at timestamp
getUrl()  : string|null
Get page URL slug
getUrlSlug()  : string
Get the URL slug for this page
getWorkflowState()  : string|null
Get workflow state
isDraft()  : bool
Check if page is a draft
isPublished()  : bool
Check if page is published
lastEditor()  : User|null
Get the user who last edited this page
makeFrontPage()  : self
Make this page the course front page
paginate()  : PaginationResult
Get paginated results with metadata
publish()  : self
Publish the page
revertToRevision()  : PageRevision
Revert to a specific revision
revision()  : PageRevision
Get a specific revision
revisions()  : array<string|int, PageRevision>
Get revisions for this page
save()  : self
Save the current page (create or update)
setApiClient()  : void
Set the API client
setAsFrontPage()  : self
Set a page as the course front page
setBlockEditorAttributes()  : void
Set block editor attributes
setBody()  : void
Set page body content
setCourse()  : void
Set the course context for page operations
setCreatedAt()  : void
Set created at timestamp
setEditingRoles()  : void
Set editing roles
setEditor()  : void
Set editor type
setFrontPage()  : void
Set front page status
setHtmlUrl()  : void
Set HTML URL
setLastEditedBy()  : void
Set last edited by user
setLockedForUser()  : void
Set locked for user status
setLockExplanation()  : void
Set lock explanation
setLockInfo()  : void
Set lock info
setPageId()  : void
Set page ID
setPageViewsCount()  : void
Set page views count
setPublishAt()  : void
Set publish at date
setPublished()  : void
Set published status
setRevisionId()  : void
Set revision ID
setTitle()  : void
Set page title
setUpdatedAt()  : void
Set updated at timestamp
setUrl()  : void
Set page URL slug
setWorkflowState()  : void
Set workflow state
toArray()  : array<string, mixed>
Convert page to array
toDtoArray()  : array<string, mixed>
Convert page to DTO array format
unpublish()  : self
Unpublish the page
update()  : self
Update a page
updateFrontPage()  : self
Update or create the course front page
updateUrlSlug()  : self
Update the URL slug for this page
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getEndpoint()  : string
Get the API endpoint for this resource
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data

Constants

EDITING_ROLES

Page editing roles constants

public mixed EDITING_ROLES = ['teachers' => 'teachers', 'students' => 'students', 'members' => 'members', 'public' => 'public']

Properties

$blockEditorAttributes

Block editor attributes (when editor is 'block_editor')

public array<string, mixed>|null $blockEditorAttributes = null

$body

Page body content (HTML)

public string|null $body = null

$createdAt

Page creation timestamp

public string|null $createdAt = null

$editingRoles

Who can edit the page

public string|null $editingRoles = null

$editor

The editor used to create/edit the page ('rce' or 'block_editor')

public string|null $editor = null

$frontPage

Whether this is the course front page

public bool|null $frontPage = null

$htmlUrl

Full Canvas URL to the page

public string|null $htmlUrl = null

$lastEditedBy

User who last edited the page

public array<string, mixed>|null $lastEditedBy = null

$lockedForUser

Whether page is locked for the current user

public bool|null $lockedForUser = null

$lockExplanation

Lock explanation if page is locked

public string|null $lockExplanation = null

$lockInfo

Lock information if page is locked

public string|null $lockInfo = null

$pageId

Page numeric ID

public int|null $pageId = null

$pageViewsCount

Number of page views

public int|null $pageViewsCount = null

$publishAt

Scheduled publication date

public string|null $publishAt = null

$published

Whether page is published

public bool|null $published = null

$revisionId

Page revision ID

public int|null $revisionId = null

$title

Page title

public string|null $title = null

$updatedAt

Page last update timestamp

public string|null $updatedAt = null

$url

Page URL slug (used as identifier)

public string|null $url = null

$workflowState

Page workflow state

public string|null $workflowState = null

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
InvalidArgumentException

__construct()

Create a new Page instance

public __construct([array<string, mixed> $data = [] ]) : mixed
Parameters
$data : array<string, mixed> = []

Page data from Canvas API

all()

Get all pages of results

public static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

checkCourse()

Check if course context is set

public static checkCourse() : bool
Tags
throws
CanvasApiException

If course is not set

Return values
bool

course()

Get the course this page belongs to

public course() : Course|null
Return values
Course|null

duplicate()

Duplicate this page

public duplicate() : self
Tags
throws
CanvasApiException
Return values
self

New duplicated page

fetchFrontPage()

Get the course front page

public static fetchFrontPage() : self|null
Tags
throws
CanvasApiException
Return values
self|null

Front page object or null if not set

find()

Find a single page by ID

public static find(int $id[, array<string, mixed> $params = [] ]) : self
Parameters
$id : int

Page ID

$params : array<string, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
self

findByUrl()

Find a single page by URL slug

public static findByUrl(string $url) : self
Parameters
$url : string

Page URL slug

Tags
throws
CanvasApiException
Return values
self

generateSlug()

Generate a URL slug from a title

public static generateSlug(string $title) : string
Parameters
$title : string

Page title

Return values
string

URL slug

get()

Fetch all pages for the course

public static get([array<string, mixed> $params = [] ]) : array<string|int, Page>
Parameters
$params : array<string, mixed> = []

Optional parameters

  • sort: Sort results by this field ('title', 'created_at', 'updated_at')
  • order: The sorting order ('asc', 'desc'). Defaults to 'asc'
  • search_term: The partial title of the pages to match and return
  • published: If true, include only published pages. If false, exclude published pages
  • include: Array or string. 'body' to include page body with each Page
Tags
throws
CanvasApiException
Return values
array<string|int, Page>

Array of Page objects

getBlockEditorAttributes()

Get block editor attributes

public getBlockEditorAttributes() : array<string, mixed>|null
Return values
array<string, mixed>|null

getBody()

Get page body content

public getBody() : string|null
Return values
string|null

getCreatedAt()

Get created at timestamp

public getCreatedAt() : string|null
Return values
string|null

getEditingRoles()

Get editing roles

public getEditingRoles() : string|null
Return values
string|null

getEditor()

Get editor type

public getEditor() : string|null
Return values
string|null

getFrontPage()

Get front page status

public getFrontPage() : bool|null
Return values
bool|null

getHtmlUrl()

Get HTML URL

public getHtmlUrl() : string|null
Return values
string|null

getLastEditedBy()

Get last edited by user

public getLastEditedBy() : array<string, mixed>|null
Return values
array<string, mixed>|null

getLockedForUser()

Get locked for user status

public getLockedForUser() : bool|null
Return values
bool|null

getLockExplanation()

Get lock explanation

public getLockExplanation() : string|null
Return values
string|null

getLockInfo()

Get lock info

public getLockInfo() : string|null
Return values
string|null

getPageId()

Get page ID

public getPageId() : int|null
Return values
int|null

getPageViewsCount()

Get page views count

public getPageViewsCount() : int|null
Return values
int|null

getPublishAt()

Get publish at date

public getPublishAt() : string|null
Return values
string|null

getPublished()

Get published status

public getPublished() : bool|null
Return values
bool|null

getRevisionId()

Get revision ID

public getRevisionId() : int|null
Return values
int|null

getSafeBody()

Get sanitized body content safe for display

public getSafeBody() : string|null

This method returns a sanitized version of the page body content with potentially dangerous HTML removed. It strips all script tags, event handlers, and other potentially malicious content while preserving safe formatting tags.

Return values
string|null

Sanitized HTML content or null if body is empty

getTitle()

Get page title

public getTitle() : string|null
Return values
string|null

getUpdatedAt()

Get updated at timestamp

public getUpdatedAt() : string|null
Return values
string|null

getUrl()

Get page URL slug

public getUrl() : string|null
Return values
string|null

getUrlSlug()

Get the URL slug for this page

public getUrlSlug() : string
Return values
string

URL slug

getWorkflowState()

Get workflow state

public getWorkflowState() : string|null
Return values
string|null

isDraft()

Check if page is a draft

public isDraft() : bool
Return values
bool

isPublished()

Check if page is published

public isPublished() : bool
Return values
bool

makeFrontPage()

Make this page the course front page

public makeFrontPage() : self
Tags
throws
CanvasApiException
Return values
self

revertToRevision()

Revert to a specific revision

public revertToRevision(int $revisionId) : PageRevision
Parameters
$revisionId : int

The revision ID to revert to

Tags
throws
CanvasApiException
Return values
PageRevision

The revision data after reverting

revision()

Get a specific revision

public revision(int|string $revisionId[, bool $summary = false ]) : PageRevision
Parameters
$revisionId : int|string

Revision ID or 'latest'

$summary : bool = false

If true, exclude page content from results

Tags
throws
CanvasApiException
Return values
PageRevision

Revision object

revisions()

Get revisions for this page

public revisions([array<string, mixed> $params = [] ]) : array<string|int, PageRevision>
Parameters
$params : array<string, mixed> = []

Query parameters

Tags
throws
CanvasApiException
Return values
array<string|int, PageRevision>

save()

Save the current page (create or update)

public save() : self
Tags
throws
CanvasApiException
Return values
self

setAsFrontPage()

Set a page as the course front page

public static setAsFrontPage(string $pageUrl) : self
Parameters
$pageUrl : string

Page URL slug to set as front page

Tags
throws
CanvasApiException
Return values
self

setBlockEditorAttributes()

Set block editor attributes

public setBlockEditorAttributes(array<string, mixed>|null $blockEditorAttributes) : void
Parameters
$blockEditorAttributes : array<string, mixed>|null

setBody()

Set page body content

public setBody(string|null $body) : void
Parameters
$body : string|null

setCourse()

Set the course context for page operations

public static setCourse(Course $course) : void
Parameters
$course : Course

The course to operate on

setCreatedAt()

Set created at timestamp

public setCreatedAt(string|null $createdAt) : void
Parameters
$createdAt : string|null

setEditingRoles()

Set editing roles

public setEditingRoles(string|null $editingRoles) : void
Parameters
$editingRoles : string|null

setEditor()

Set editor type

public setEditor(string|null $editor) : void
Parameters
$editor : string|null

setFrontPage()

Set front page status

public setFrontPage(bool|null $frontPage) : void
Parameters
$frontPage : bool|null

setHtmlUrl()

Set HTML URL

public setHtmlUrl(string|null $htmlUrl) : void
Parameters
$htmlUrl : string|null

setLastEditedBy()

Set last edited by user

public setLastEditedBy(array<string, mixed>|null $lastEditedBy) : void
Parameters
$lastEditedBy : array<string, mixed>|null

setLockedForUser()

Set locked for user status

public setLockedForUser(bool|null $lockedForUser) : void
Parameters
$lockedForUser : bool|null

setLockExplanation()

Set lock explanation

public setLockExplanation(string|null $lockExplanation) : void
Parameters
$lockExplanation : string|null

setLockInfo()

Set lock info

public setLockInfo(string|null $lockInfo) : void
Parameters
$lockInfo : string|null

setPageId()

Set page ID

public setPageId(int|null $pageId) : void
Parameters
$pageId : int|null

setPageViewsCount()

Set page views count

public setPageViewsCount(int|null $pageViewsCount) : void
Parameters
$pageViewsCount : int|null

setPublishAt()

Set publish at date

public setPublishAt(string|null $publishAt) : void
Parameters
$publishAt : string|null

setPublished()

Set published status

public setPublished(bool|null $published) : void
Parameters
$published : bool|null

setRevisionId()

Set revision ID

public setRevisionId(int|null $revisionId) : void
Parameters
$revisionId : int|null

setTitle()

Set page title

public setTitle(string|null $title) : void
Parameters
$title : string|null

setUpdatedAt()

Set updated at timestamp

public setUpdatedAt(string|null $updatedAt) : void
Parameters
$updatedAt : string|null

setUrl()

Set page URL slug

public setUrl(string|null $url) : void
Parameters
$url : string|null

setWorkflowState()

Set workflow state

public setWorkflowState(string|null $workflowState) : void
Parameters
$workflowState : string|null

toArray()

Convert page to array

public toArray() : array<string, mixed>
Return values
array<string, mixed>

toDtoArray()

Convert page to DTO array format

public toDtoArray() : array<string, mixed>
Return values
array<string, mixed>

update()

Update a page

public static update(string $url, array<string, mixed>|UpdatePageDTO $data) : self
Parameters
$url : string

Page URL slug

$data : array<string, mixed>|UpdatePageDTO

Page data

Tags
throws
CanvasApiException
Return values
self

Updated Page object

updateFrontPage()

Update or create the course front page

public static updateFrontPage(array<string, mixed>|UpdatePageDTO $data) : self
Parameters
$data : array<string, mixed>|UpdatePageDTO

Page data

Tags
throws
CanvasApiException
Return values
self

The updated front page

updateUrlSlug()

Update the URL slug for this page

public updateUrlSlug(string $newSlug) : self
Parameters
$newSlug : string

New URL slug

Tags
throws
CanvasApiException
Return values
self

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the API endpoint for this resource

protected static getEndpoint() : string
Tags
throws
CanvasApiException
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

        
On this page

Search results