public function EntityLegalDocumentVersionForm::buildForm in Entity Legal 3.0.x
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- src/
Form/ EntityLegalDocumentVersionForm.php, line 27
Class
- EntityLegalDocumentVersionForm
- Class EntityLegalDocumentVersionForm.
Namespace
Drupal\entity_legal\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Provide default values if a published version already exists.
if ($this->entity && $this->entity
->isNew()) {
$document = $this->entity
->getDocument();
if ($document instanceof EntityLegalDocumentInterface) {
$published_version = $document
->getPublishedVersion();
if ($published_version) {
$clone = $published_version
->createDuplicate();
// Unset properties that shouldn't be copied over.
$clone
->set('name', NULL);
$clone
->set('created', REQUEST_TIME);
$clone
->set('changed', REQUEST_TIME);
$clone
->set('published', FALSE);
$this
->setEntity($clone);
}
}
$form['langcode'] = [
'#title' => $this
->t('Language'),
'#type' => 'language_select',
'#access' => TRUE,
'#default_value' => $this->entity
->language()
->getId(),
'#languages' => LanguageInterface::STATE_ALL,
];
}
return parent::buildForm($form, $form_state);
}