Craft Themes (4.x)

LayoutService extends Service
in package

Table of Contents

CONFIG_KEY  = 'themes.layouts'
DEFAULT_HANDLE  = 'default'
EVENT_AFTER_DELETE  = 'after_delete'
EVENT_AFTER_SAVE  = 'after_save'
EVENT_AVAILABLE_LAYOUTS  = 'available_layouts'
EVENT_BEFORE_APPLY_DELETE  = 'before_apply_delete'
EVENT_BEFORE_DELETE  = 'before_delete'
EVENT_BEFORE_SAVE  = 'before_save'
EVENT_REGISTER_TYPES  = 'register_types'
EVENT_RESOLVE_REQUEST_LAYOUT  = 'resolve_request_layout'
USER_HANDLE  = 'user'
$isInstalling  : bool
Marker when layouts are being installed
$_layouts  : Collection
$_types  : array<string|int, mixed>
copyIntoCustom()  : LayoutInterface
Copy a layout into custom one
create()  : LayoutInterface
Create a layout from config
createCustom()  : CustomLayout
Create a custom layout
deleteCustom()  : bool
Delete a custom layout
get()  : LayoutInterface|null
Get a layout
getAll()  : Collection
All layouts getter
getBlockLayouts()  : array<string|int, LayoutInterface>
Get all layouts that can have blocks indexed by theme's handle
getById()  : LayoutInterface
Get layout by id
getByUid()  : LayoutInterface
Get layout by uid
getCustom()  : CustomLayout|null
Get a custom layout by handle
getDefault()  : LayoutInterface|null
Get default layout for a theme
getForTheme()  : array<string|int, LayoutInterface>
Get all layouts for a theme
getForType()  : array<string|int, LayoutInterface>
Returns all layouts for a type
getRecordByUid()  : LayoutRecord
Get layout record by uid, or a new one if it's not found
getType()  : string|null
Get the type of a layout
getTypes()  : array<string|int, mixed>
Get defined layouts types
getWithDisplays()  : array<string|int, LayoutInterface>
Get all layouts with displays indexed by theme's handle
handleChanged()  : mixed
Handles a change in layout config
handleDeleted()  : mixed
Handles a deletion in layout config
installAll()  : mixed
(Re)create all layouts for all themes.
installForTheme()  : bool
(Re)create layouts for a theme, will deletes orphans.
onCraftElementDeleted()  : mixed
Callback when an element (entry type, category group etc) is deleted
onCraftElementSaved()  : mixed
Callback when an element (entry type, category group etc) is saved
rebuildConfig()  : mixed
Respond to rebuild config event
resolveForRequest()  : LayoutInterface|null
Resolve current layout.
save()  : bool
Save a layout
uninstallForTheme()  : bool
Deletes all layouts for a theme.
withDisplays()  : array<string|int, LayoutInterface>
Get all layouts that have displays
add()  : mixed
Add a layout to internal cache
blockCacheService()  : BlockCacheService
Get the block cache service
blockProviderService()  : BlockProvidersService
Get the block providers service
blocksService()  : BlockService
Get the blocks service
createCategoryLayouts()  : array<string|int, LayoutInterface>
Creates all categories layouts
createEntryLayouts()  : array<string|int, LayoutInterface>
Creates all entries layouts
createGlobalsLayouts()  : array<string|int, LayoutInterface>
Creates all globals layouts
createTagsLayouts()  : array<string|int, LayoutInterface>
Creates all tags layouts
createVolumesLayouts()  : array<string|int, LayoutInterface>
Creates all volumes layouts
delete()  : bool
Deletes a layout
displayService()  : DisplayService
Get the display service
eagerLoadingService()  : EagerLoadingService
Get the eager loading service
fieldDisplayersService()  : FieldDisplayerService
Get the field displayers service
fieldsService()  : FieldsService
Get the fields service
fileDisplayerService()  : FileDisplayerService
Get the file displayers service
getAvailable()  : array<string|int, LayoutInterface>
Get all available layouts
getCustomLayouts()  : array<string|int, LayoutInterface>
Get all custom layouts for a theme
getThemeHandle()  : string
Get theme handle from a theme parameter
groupsService()  : GroupsService
Get the groups service
installLayoutData()  : bool
Install layout data
layoutService()  : LayoutService
Get the layout service
matrixService()  : MatrixService
Get the matrix service
themesRegistry()  : ThemesRegistry
Get the themes registry
triggerEvent()  : mixed
Triggers an event
viewModesService()  : ViewModeService
Get the view mode service
viewService()  : ViewService
Get the view service

Constants

EVENT_AFTER_DELETE

public mixed EVENT_AFTER_DELETE = 'after_delete'

EVENT_AFTER_SAVE

public mixed EVENT_AFTER_SAVE = 'after_save'

EVENT_AVAILABLE_LAYOUTS

public mixed EVENT_AVAILABLE_LAYOUTS = 'available_layouts'
Tags
since
3.1.0

EVENT_BEFORE_APPLY_DELETE

public mixed EVENT_BEFORE_APPLY_DELETE = 'before_apply_delete'

EVENT_BEFORE_DELETE

public mixed EVENT_BEFORE_DELETE = 'before_delete'

EVENT_BEFORE_SAVE

public mixed EVENT_BEFORE_SAVE = 'before_save'

EVENT_REGISTER_TYPES

public mixed EVENT_REGISTER_TYPES = 'register_types'
Tags
since
3.1.0

EVENT_RESOLVE_REQUEST_LAYOUT

public mixed EVENT_RESOLVE_REQUEST_LAYOUT = 'resolve_request_layout'
Tags
since
3.1.0

Properties

$isInstalling

Marker when layouts are being installed

public static bool $isInstalling = false

$_types

protected array<string|int, mixed> $_types
Tags
since
3.1.0

Methods

createCustom()

Create a custom layout

public createCustom(array<string|int, mixed> $data) : CustomLayout
Parameters
$data : array<string|int, mixed>
Return values
CustomLayout

getAll()

All layouts getter

public getAll() : Collection
Return values
Collection

getForTheme()

Get all layouts for a theme

public getForTheme(string|ThemeInterface $theme[, bool|null $withHasDisplays = null ][, bool|null $withHasBlocks = null ]) : array<string|int, LayoutInterface>
Parameters
$theme : string|ThemeInterface

theme instance or theme handle

$withHasDisplays : bool|null = null
$withHasBlocks : bool|null = null
Return values
array<string|int, LayoutInterface>

getRecordByUid()

Get layout record by uid, or a new one if it's not found

public getRecordByUid(string $uid) : LayoutRecord
Parameters
$uid : string
Return values
LayoutRecord

getTypes()

Get defined layouts types

public getTypes() : array<string|int, mixed>
Tags
since
3.1.0
Return values
array<string|int, mixed>

handleChanged()

Handles a change in layout config

public handleChanged(ConfigEvent $event) : mixed
Parameters
$event : ConfigEvent
Return values
mixed

handleDeleted()

Handles a deletion in layout config

public handleDeleted(ConfigEvent $event) : mixed
Parameters
$event : ConfigEvent
Return values
mixed

installAll()

(Re)create all layouts for all themes.

public installAll() : mixed
Return values
mixed

onCraftElementDeleted()

Callback when an element (entry type, category group etc) is deleted

public onCraftElementDeleted(string $uid) : mixed
Parameters
$uid : string
Return values
mixed

onCraftElementSaved()

Callback when an element (entry type, category group etc) is saved

public onCraftElementSaved(string $type[, string $uid = '' ]) : mixed
Parameters
$type : string
$uid : string = ''
Return values
mixed

rebuildConfig()

Respond to rebuild config event

public rebuildConfig(RebuildConfigEvent $e) : mixed
Parameters
$e : RebuildConfigEvent
Return values
mixed

createCategoryLayouts()

Creates all categories layouts

protected createCategoryLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

createEntryLayouts()

Creates all entries layouts

protected createEntryLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

createGlobalsLayouts()

Creates all globals layouts

protected createGlobalsLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

createTagsLayouts()

Creates all tags layouts

protected createTagsLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

createVolumesLayouts()

Creates all volumes layouts

protected createVolumesLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

getCustomLayouts()

Get all custom layouts for a theme

protected getCustomLayouts(string $themeHandle) : array<string|int, LayoutInterface>
Parameters
$themeHandle : string
Return values
array<string|int, LayoutInterface>

matrixService()

Get the matrix service

protected matrixService() : MatrixService
Return values
MatrixService

triggerEvent()

Triggers an event

protected triggerEvent(string $type, Event $event) : mixed
Parameters
$type : string
$event : Event
Return values
mixed

Search results