You are here

public function PriceListForm::form in Commerce Pricelist 8

Same name and namespace in other branches
  1. 8.2 src/Form/PriceListForm.php \Drupal\commerce_pricelist\Form\PriceListForm::form()

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/PriceListForm.php, line 90

Class

PriceListForm
Form controller for Price list edit forms.

Namespace

Drupal\commerce_pricelist\Form

Code

public function form(array $form, FormStateInterface $form_state) {

  /* @var \Drupal\commerce_pricelist\Entity\PriceList $priceList */
  $priceList = $this->entity;
  $form = parent::form($form, $form_state);
  $form['#tree'] = TRUE;
  $form['changed'] = [
    '#type' => 'hidden',
    '#default_value' => $priceList
      ->getChangedTime(),
  ];
  $last_saved = t('Not saved yet');
  if (!$priceList
    ->isNew()) {
    $last_saved = $this->dateFormatter
      ->format($priceList
      ->getChangedTime(), 'short');
  }
  $form['meta'] = [
    '#attributes' => [
      'class' => [
        'entity-meta__header',
      ],
    ],
    '#type' => 'container',
    '#weight' => 100,
    'published' => [
      '#type' => 'html_tag',
      '#tag' => 'h3',
      '#value' => $priceList
        ->isPublished() ? $this
        ->t('Published') : $this
        ->t('Not published'),
      '#access' => !$priceList
        ->isNew(),
      '#attributes' => [
        'class' => [
          'entity-meta__title',
        ],
      ],
    ],
    'changed' => [
      '#type' => 'item',
      '#wrapper_attributes' => [
        'class' => [
          'entity-meta__last-saved',
          'container-inline',
        ],
      ],
      '#markup' => '<h4 class="label inline">' . $this
        ->t('Last saved') . '</h4> ' . $last_saved,
    ],
    'author' => [
      '#type' => 'item',
      '#wrapper_attributes' => [
        'class' => [
          'author',
          'container-inline',
        ],
      ],
      '#markup' => '<h4 class="label inline">' . $this
        ->t('Author') . '</h4> ' . $priceList
        ->getOwner()
        ->getDisplayName(),
    ],
  ];
  return $form;
}