www.hubleto.eu Reddit User Guide Stack Overflow LinkedIn Report an issue

Form description

describeForm() returns a Hubleto\Framework\Description\Form:

apps/Deals/Models/Deal.php (excerpt)
  public function describeForm(): \Hubleto\Framework\Description\Form
  {
    $description = parent::describeForm();

    /** @var Workflow */
    $mWorkflow = $this->getModel(Workflow::class);
    $description->defaultValues = $mWorkflow->applyDefaultWorkflow([], 'deals');

    /** @var CurrencyService */
    $currencyService = $this->getService(CurrencyService::class);
    $description->defaultValues["id_currency"] = $currencyService->getDefaultCurrencyId();

    return $description;
  }

Properties

Property Meaning
ui Texts and buttons of the form (below).
permissions canCreate, canRead, canUpdate, canDelete.
inputs The inputs of the columns.
defaultValues Values of a new record. Set them with setDefaultValue($column, $value).
includeRelations The relations that are loaded together with the record.

Properties.

The ui array

Key Default Meaning
title, subTitle '' Heading.
showSaveButton, showDeleteButton true Buttons.
showCopyButton false The "copy" button.
saveButtonText, addButtonText, copyButtonText, deleteButtonText '' Texts of the buttons.
headerClassName '' CSS classes of the header.

Keys of ui.

Methods

Method Purpose
show([...]), hide([...]) Turn buttons and other parts on or off.
setDefaultValue($column, $value) Default value of a column in a new record.

Methods.

Default values and the current user

Defaults that depend on the situation belong into describeForm(); constant defaults into the column (setDefaultValue()). Deal selects the default workflow and currency of a new deal:

apps/Deals/Models/Deal.php (excerpt)
  public function describeForm(): \Hubleto\Framework\Description\Form
  {
    $description = parent::describeForm();

    /** @var Workflow */
    $mWorkflow = $this->getModel(Workflow::class);
    $description->defaultValues = $mWorkflow->applyDefaultWorkflow([], 'deals');

    /** @var CurrencyService */
    $currencyService = $this->getService(CurrencyService::class);
    $description->defaultValues["id_currency"] = $currencyService->getDefaultCurrencyId();

    return $description;
  }

More in describeForm().