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::get();

// Get paginated tabs
$paginationResult = Tab::paginate();

// 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::get()[0];
$tab->position = 5;
$tab->hidden = true;
$success = $tab->save();

Table of Contents

Properties

$hidden  : bool|null
Whether the tab is hidden from students
$htmlUrl  : 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)
$course  : Course|null
$methodAliases  : array<string, array<string|int, string>>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Create a new Tab instance
all()  : array<string|int, static>
Get all pages of results
checkCourse()  : bool
Check if course context is set
find()  : static
Find a single tab by ID
get()  : array<string|int, static>
Get first page of results
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
overrideApiClient()  : void
Set an API client for this class only, leaving other resources on the shared default.
paginate()  : PaginationResult
Get paginated results with metadata
resetApiClients()  : void
Clear the shared default client and all per-class overrides.
save()  : self
Save the current tab (update only)
setApiClient()  : void
Set the shared default API client used by ALL resource classes.
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
stream()  : Generator<int, static>
Stream all items across all pages one at a time.
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
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getAliasMap()  : array<string, string>
Build a flat alias-to-method lookup from $methodAliases.
getApiClient()  : HttpClientInterface
Get the API client, initializing if necessary
getContextCourseId()  : int
Get the Course ID from context, ensuring course is set
getCourse()  : Course
Get the Course instance, ensuring it is set
getEndpoint()  : string
Get the API endpoint for this resource
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
hydrate()  : void
Assign API response data to properties with type coercion.
parseJsonResponse()  : array<string|int, mixed>
Parse JSON response from API safely handling StreamInterface
populate()  : void
Populate the object with new data
validateContext()  : void
Validate a context type path segment against an allowlist.

Properties

$hidden

Whether the tab is hidden from students

public bool|null $hidden = null

$htmlUrl

HTML URL of the tab

public string|null $htmlUrl = 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

$course

protected static Course|null $course = null

$methodAliases

Define method aliases

protected static array<string, array<string|int, string>> $methodAliases = ['get' => ['fetch', 'list'], 'all' => ['fetchAllPages', 'getAll', 'fetchAll'], 'paginate' => ['getPaginated', 'withPagination'], '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 Tab instance

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

Tab 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

find()

Find a single tab by ID

public static find(int $id[, array<string|int, mixed> $params = [] ]) : 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

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

Optional query parameters

Tags
throws
CanvasApiException

Always throws as this operation is not supported

Return values
static

get()

Get first page of results

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

Query parameters

Return values
array<string|int, 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

resetApiClients()

Clear the shared default client and all per-class overrides.

public static resetApiClients() : void

save()

Save the current tab (update only)

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

setApiClient()

Set the shared default API client used by ALL resource classes.

public static setApiClient(HttpClientInterface $apiClient) : void

Calling this on any resource (e.g. Course::setApiClient()) replaces the client for every resource, because relationship methods cross class boundaries ($course->enrollments() calls Enrollment internally). Use overrideApiClient() to scope a client to a single class, and resetApiClients() in test teardown to avoid state leaking.

Parameters
$apiClient : HttpClientInterface

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 $htmlUrl) : void
Parameters
$htmlUrl : 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

stream()

Stream all items across all pages one at a time.

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

Unlike all(), only one page of raw data is held in memory at a time, making this safe for very large datasets (e.g. tens of thousands of enrollments):

foreach (User::stream(['per_page' => 100]) as $user) {
    processUser($user);
}
Parameters
$params : array<string|int, mixed> = []

Query parameters for the request

Tags
throws
CanvasApiException
Return values
Generator<int, static>

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>

getAliasMap()

Build a flat alias-to-method lookup from $methodAliases.

protected static getAliasMap() : array<string, string>
Return values
array<string, string>

getContextCourseId()

Get the Course ID from context, ensuring course is set

protected static getContextCourseId() : int
Tags
throws
CanvasApiException

if course is not set

Return values
int

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

hydrate()

Assign API response data to properties with type coercion.

protected hydrate(array<string|int, mixed> $data) : void

Shared by the constructor and populate() so objects keep the same type guarantees after save()/update() round-trips as on creation.

Parameters
$data : array<string|int, mixed>

parseJsonResponse()

Parse JSON response from API safely handling StreamInterface

protected static parseJsonResponse(ResponseInterface $response) : array<string|int, mixed>
Parameters
$response : ResponseInterface
Return values
array<string|int, mixed>

populate()

Populate the object with new data

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

validateContext()

Validate a context type path segment against an allowlist.

protected static validateContext(string|null $contextType, array<int, string> $allowed) : void

Context types are interpolated into URL paths; validating against the contexts Canvas actually supports prevents crafted values from injecting extra path segments or query parameters.

Parameters
$contextType : string|null

The context type (plural, e.g. 'courses'); null is ignored

$allowed : array<int, string>

Allowed context types

Tags
throws
CanvasApiException

If the context type is not allowed

On this page

Search results