Documentation

FormHelper
in package

Provides helper functions for form operations in the LGMS module.

This class includes methods for AJAX responses, updating parent nodes, setting form data, and more, aiding in the manipulation and handling of form submissions and operations within the LGMS (Library Guide Management System) module.

Table of Contents

Methods

add_child()  : void
Adds a child entity to a parent's field.
clone_boxes()  : void
Clones all boxes from one guide/page to another.
clone_items()  : void
Clones all boxes from one guide/page to another.
clone_pages()  : void
Clones the pages from one guide to another, optionally creating references.
create_link()  : EntityInterface
Creates a new link entity from provided content and associates it with a box.
delete_all_boxes()  : void
Deletes all boxes associated with a parent entity.
delete_box()  : void
Deletes a specific box and its content.
deletePages()  : void
Deletes the specified pages and optionally their subpages.
draft_field()  : mixed
get_content_items()  : array<string|int, mixed>
Provides a list of content item field names.
get_filled_field()  : string
Determines the field of the current item that is filled.
get_item_options()  : array<string|int, mixed>
Generates a list of options for entity reference fields, optionally grouped.
get_new_order()  : array<string|int, mixed>
Processes the reordered list to update the entity storage accordingly.
get_pages_options()  : array<string|int, mixed>
get_position_options()  : array<string|int, mixed>
get_reorder_table()  : void
Generates the reorder table for entities.
remove_child()  : void
Removes a child entity from a parent's field.
set_form_data()  : void
Sets initial data for forms, including hidden fields for IDs and AJAX wrappers.
set_prefix()  : void
Sets the AJAX wrapper prefixes and suffixes for the form.
submitModalAjax()  : AjaxResponse
Handles AJAX submissions and redirects or updates the page accordingly.
update_link()  : void
Updates the content link with new information from form submission.
updateParent()  : void
Updates the 'changed' timestamp of the parent node and potentially its parent guide.

Methods

add_child()

Adds a child entity to a parent's field.

public add_child(EntityInterface $parent, EntityInterface $child, string $field) : void
Parameters
$parent : EntityInterface

The parent entity.

$child : EntityInterface

The child entity to add.

$field : string

The field to which the child will be added.

Tags
throws
EntityStorageException

clone_boxes()

Clones all boxes from one guide/page to another.

public clone_boxes(EntityInterface $page, EntityInterface $new_page[, bool $copy_content = true ]) : void
Parameters
$page : EntityInterface

The source page.

$new_page : EntityInterface

The destination page.

$copy_content : bool = true
Tags
throws
EntityStorageException

clone_items()

Clones all boxes from one guide/page to another.

public clone_items(EntityInterface $box, EntityInterface $new_box, bool $copy_content) : void
Parameters
$box : EntityInterface

The source page.

$new_box : EntityInterface

The destination page.

$copy_content : bool
Tags
throws
EntityStorageException

clone_pages()

Clones the pages from one guide to another, optionally creating references.

public clone_pages(EntityInterface $parent, EntityInterface $new_parent[, bool $ref = false ]) : void
Parameters
$parent : EntityInterface

The source guide.

$new_parent : EntityInterface

The destination guide.

$ref : bool = false

Whether to create references instead of duplicates.

Tags
throws
EntityStorageException

Creates a new link entity from provided content and associates it with a box.

public create_link(EntityInterface $new_content, string $current_box) : EntityInterface
Parameters
$new_content : EntityInterface

The new content entity to link.

$current_box : string

The ID of the box to link the content to.

Tags
throws
EntityStorageException
Return values
EntityInterface

The newly created link entity.

delete_all_boxes()

Deletes all boxes associated with a parent entity.

public delete_all_boxes(EntityInterface $parent) : void
Parameters
$parent : EntityInterface

The parent entity from which boxes will be deleted.

delete_box()

Deletes a specific box and its content.

public delete_box(EntityInterface $box) : void
Parameters
$box : EntityInterface

The box entity to delete.

deletePages()

Deletes the specified pages and optionally their subpages.

public deletePages(EntityInterface $parent, bool $delete_sub) : void
Parameters
$parent : EntityInterface

The parent entity from which pages will be deleted.

$delete_sub : bool

Whether to delete subpages of the specified pages.

Tags
throws
EntityStorageException

draft_field()

public draft_field(array<string|int, mixed> &$form, FormStateInterface $form_state, mixed $content, mixed $item, bool $edit) : mixed
Parameters
$form : array<string|int, mixed>
$form_state : FormStateInterface
$content : mixed
$item : mixed
$edit : bool

get_content_items()

Provides a list of content item field names.

public get_content_items() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of field names for content items.

get_filled_field()

Determines the field of the current item that is filled.

public get_filled_field( $current_item) : string
Parameters
$current_item :

The current item entity to check.

Return values
string

The field name that is filled for the current item.

get_item_options()

Generates a list of options for entity reference fields, optionally grouped.

public get_item_options(string $content_type[, string $group_by = '' ]) : array<string|int, mixed>
Parameters
$content_type : string

The content type of entities to include.

$group_by : string = ''

(optional) The field by which to group the options.

Return values
array<string|int, mixed>

An array of options for entity reference fields.

get_new_order()

Processes the reordered list to update the entity storage accordingly.

public get_new_order(array<string|int, mixed> $values, array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>

The form values containing the new order.

$items : array<string|int, mixed>

The original items to reorder.

Return values
array<string|int, mixed>

The reordered items.

get_pages_options()

public get_pages_options(string $guide_id[, bool $include_guide = true ]) : array<string|int, mixed>
Parameters
$guide_id : string
$include_guide : bool = true
Return values
array<string|int, mixed>

get_position_options()

public get_position_options(FormStateInterface $form_state, string $guide_id[, bool $onlyWithSubpages = false ]) : array<string|int, mixed>
Parameters
$form_state : FormStateInterface
$guide_id : string
$onlyWithSubpages : bool = false
Return values
array<string|int, mixed>

get_reorder_table()

Generates the reorder table for entities.

public get_reorder_table(array<string|int, mixed> &$form, mixed $list) : void
Parameters
$form : array<string|int, mixed>

The form array to append the reorder table to.

$list : mixed

The list of entities to be reordered.

remove_child()

Removes a child entity from a parent's field.

public remove_child( $page, EntityInterface $child_to_remove, string $field) : void
Parameters
$page :
$child_to_remove : EntityInterface

The child entity to remove.

$field : string

The field from which the child will be removed.

set_form_data()

Sets initial data for forms, including hidden fields for IDs and AJAX wrappers.

public set_form_data(array<string|int, mixed> &$form, object $ids, string $form_id) : void
Parameters
$form : array<string|int, mixed>

The form array.

$ids : object

An object containing identifiers required for the form.

$form_id : string

The form ID used for setting prefixes and suffixes.

set_prefix()

Sets the AJAX wrapper prefixes and suffixes for the form.

public set_prefix(array<string|int, mixed> &$form, string $id) : void
Parameters
$form : array<string|int, mixed>

The form array.

$id : string

The form ID to use as the AJAX wrapper ID.

submitModalAjax()

Handles AJAX submissions and redirects or updates the page accordingly.

public submitModalAjax(array<string|int, mixed> &$form, FormStateInterface $form_state, string $message[, string $form_id = '#modal-form' ]) : AjaxResponse
Parameters
$form : array<string|int, mixed>

The form array.

$form_state : FormStateInterface

The state of the form.

$message : string

The message to display upon successful submission.

$form_id : string = '#modal-form'

The CSS ID of the form element, defaults to '#modal-form'.

Tags
throws
EntityMalformedException
Return values
AjaxResponse

The AJAX response to be returned.

Updates the content link with new information from form submission.

public update_link(array<string|int, mixed> &$form, FormStateInterface $form_state, EntityInterface $current_item) : void
Parameters
$form : array<string|int, mixed>

The form array.

$form_state : FormStateInterface

The current state of the form.

$current_item : EntityInterface

The content link entity being updated.

Tags
throws
EntityStorageException

updateParent()

Updates the 'changed' timestamp of the parent node and potentially its parent guide.

public updateParent(array<string|int, mixed> &$form, FormStateInterface $form_state) : void
Parameters
$form : array<string|int, mixed>

The form array.

$form_state : FormStateInterface

The state of the form.

Tags
throws
EntityStorageException

        
On this page

Search results