Documentation

Tab extends AbstractBaseApi
in package

Canvas LMS Tabs API

Provides functionality to manage course tabs in Canvas LMS. This class handles listing and updating tabs for a specific course.

Usage Examples:

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

// List all tabs for the course
$tabs = Tab::fetchAll();

// Get paginated tabs
$paginatedTabs = Tab::fetchAllPaginated();
$paginationResult = Tab::fetchPage();

// Update a tab
$updatedTab = Tab::update('assignments', ['position' => 3, 'hidden' => false]);

// Update using DTO
$updateDto = new UpdateTabDTO(position: 2, hidden: true);
$updatedTab = Tab::update('home', $updateDto);

// Update using instance method
$tab = Tab::fetchAll()[0];
$tab->position = 5;
$tab->hidden = true;
$success = $tab->save();

Table of Contents

Properties

$hidden  : bool|null
Whether the tab is hidden from students
$html_url  : string|null
HTML URL of the tab
$id  : string|null
Unique identifier for the tab
$label  : string|null
Display label for the tab
$position  : int|null
Position of the tab in the navigation (1-based)
$type  : string|null
Type of tab (internal or external)
$visibility  : string|null
Visibility level of the tab (public, members, admins, none)
$apiClient  : HttpClientInterface
$course  : Course
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Create a new Tab instance
checkCourse()  : bool
Check if course context is set
fetchAll()  : array<string|int, Tab>
Fetch all tabs for the course
fetchAllPages()  : array<string|int, Tab>
Fetch all pages of tabs
fetchAllPaginated()  : PaginatedResponse
Fetch all tabs with pagination support
fetchPage()  : PaginationResult
Fetch a single page of tabs
find()  : static
Find a single tab by ID
getHidden()  : bool|null
Get hidden status
getHtmlUrl()  : string|null
Get HTML URL
getId()  : string|null
Get ID
getLabel()  : string|null
Get label
getPosition()  : int|null
Get position
getType()  : string|null
Get type
getVisibility()  : string|null
Get visibility
save()  : bool
Save the current tab (update only)
setApiClient()  : void
Set the API client
setCourse()  : void
Set the course context for tab operations
setHidden()  : void
Set hidden status
setHtmlUrl()  : void
Set HTML URL
setId()  : void
Set ID
setLabel()  : void
Set label
setPosition()  : void
Set position
setType()  : void
Set type
setVisibility()  : void
Set visibility
toArray()  : array<string, mixed>
Convert tab to array
toDtoArray()  : array<string, mixed>
Convert tab to DTO array format
update()  : self
Update a tab
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
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
fetchAllPagesAsModels()  : array<string|int, static>
Helper method to fetch all pages and convert to model instances
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data

Properties

$hidden

Whether the tab is hidden from students

public bool|null $hidden = null

$html_url

HTML URL of the tab

public string|null $html_url = null

$id

Unique identifier for the tab

public string|null $id = null

$label

Display label for the tab

public string|null $label = null

$position

Position of the tab in the navigation (1-based)

public int|null $position = null

$type

Type of tab (internal or external)

public string|null $type = null

$visibility

Visibility level of the tab (public, members, admins, none)

public string|null $visibility = null

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['fetchAll' => ['all', 'get', 'getAll'], 'find' => ['one', 'getOne'], 'fetchAllPaginated' => ['allPaginated', 'getPaginated'], 'fetchAllPages' => ['allPages', 'getPages'], 'fetchPage' => ['page', 'getPage']]

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>

__construct()

Create a new Tab instance

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

Tab data from Canvas API

checkCourse()

Check if course context is set

public static checkCourse() : bool
Tags
throws
CanvasApiException

If course is not set

Return values
bool

fetchAll()

Fetch all tabs for the course

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

Optional parameters

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

Array of Tab objects

fetchAllPages()

Fetch all pages of tabs

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

Optional parameters

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

Array of Tab objects from all pages

fetchAllPaginated()

Fetch all tabs with pagination support

public static fetchAllPaginated([array<string, mixed> $params = [] ]) : PaginatedResponse
Parameters
$params : array<string, mixed> = []

Optional parameters

Tags
throws
CanvasApiException
Return values
PaginatedResponse

find()

Find a single tab by ID

public static find(int $id) : static

Note: Canvas API doesn't support finding individual tabs by ID. This method throws an exception as it's not supported.

Parameters
$id : int

Tab ID

Tags
throws
CanvasApiException

Always throws as this operation is not supported

Return values
static

getHidden()

Get hidden status

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

getHtmlUrl()

Get HTML URL

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

getId()

Get ID

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

getLabel()

Get label

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

getPosition()

Get position

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

getType()

Get type

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

getVisibility()

Get visibility

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

save()

Save the current tab (update only)

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

True if save was successful, false otherwise

setCourse()

Set the course context for tab operations

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

The course to operate on

setHidden()

Set hidden status

public setHidden(bool|null $hidden) : void
Parameters
$hidden : bool|null

setHtmlUrl()

Set HTML URL

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

setId()

Set ID

public setId(string|null $id) : void
Parameters
$id : string|null

setLabel()

Set label

public setLabel(string|null $label) : void
Parameters
$label : string|null

setPosition()

Set position

public setPosition(int|null $position) : void
Parameters
$position : int|null

setType()

Set type

public setType(string|null $type) : void
Parameters
$type : string|null

setVisibility()

Set visibility

public setVisibility(string|null $visibility) : void
Parameters
$visibility : string|null

toArray()

Convert tab to array

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

toDtoArray()

Convert tab to DTO array format

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

update()

Update a tab

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

Tab ID

$data : array<string, mixed>|UpdateTabDTO

Tab data

Tags
throws
CanvasApiException
Return values
self

Updated Tab object

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>

fetchAllPagesAsModels()

Helper method to fetch all pages and convert to model instances

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

The API endpoint path

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

Query parameters for the request

Return values
array<string|int, static>

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