Documentation

AddBookForm extends FormBase
in package

Form handler for adding and editing book entities.

Provides a form for adding new book entities to the system or editing existing ones. It supports different types of book entities (print and eBook), manages cover image uploads, and facilitates the dynamic adjustment of form fields based on the book type.

Table of Contents

Methods

buildForm()  : array<string|int, mixed>
Builds the add/edit book form.
getFormId()  : string
{@inheritdoc}
submitAjax()  : AjaxResponse
Handles AJAX form submission for the book form.
submitForm()  : void
Handles the form submission.
validateFields()  : void
Custom validation for the AddBookForm.
handleUserPicture()  : void
Manages the file usage for an uploaded book cover picture.

Methods

buildForm()

Builds the add/edit book form.

public buildForm(array<string|int, mixed> $form, FormStateInterface $form_state[, mixed $ids = null ]) : array<string|int, mixed>
Parameters
$form : array<string|int, mixed>

The initial form array.

$form_state : FormStateInterface

The state of the form.

$ids : mixed = null

Optional parameters passed to the form.

Return values
array<string|int, mixed>

The form array with all form elements added.

getFormId()

{@inheritdoc}

public getFormId() : string
Return values
string

submitAjax()

Handles AJAX form submission for the book form.

public submitAjax(array<string|int, mixed> &$form, FormStateInterface $form_state) : AjaxResponse

Provides AJAX support to submit the form, allowing for a smoother user experience without requiring a page reload.

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

The form array.

$form_state : FormStateInterface

The state of the form.

Tags
throws
EntityMalformedException

If there's an issue with the entity data.

Return values
AjaxResponse

The response for the AJAX request.

submitForm()

Handles the form submission.

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

Processes the input from the form, creating or updating a book entity with the provided values. Manages file usage for uploaded images to ensure they are not removed by the system if unused elsewhere.

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

The form array.

$form_state : FormStateInterface

The state of the form.

Tags
throws
EntityStorageException

If there's an issue saving the entity.

validateFields()

Custom validation for the AddBookForm.

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

Validates specific fields based on the selected book type and other criteria, ensuring required information is provided before submission.

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

The form array.

$form_state : FormStateInterface

The state of the form.

handleUserPicture()

Manages the file usage for an uploaded book cover picture.

protected handleUserPicture(EntityInterface $node, FormStateInterface $form_state) : void

Ensures the uploaded file is marked as permanent and records its usage, preventing Drupal from automatically removing it as unused.

Parameters
$node : EntityInterface

The book entity to associate the file with.

$form_state : FormStateInterface

The state of the form.

Tags
throws
EntityStorageException

If there's an issue saving the file entity.


        
On this page

Search results