public function RecentlyReadTypeForm::form in Recently Read 8
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ RecentlyReadTypeForm.php, line 58
Class
- RecentlyReadTypeForm
- Class RecentlyReadTypeForm.
Namespace
Drupal\recently_read\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$entity = $this->entity;
$bundles = $this->bundleInfo
->getBundleInfo($entity
->id());
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Entity type'),
'#default_value' => $entity
->label(),
'#disabled' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $entity
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\recently_read\\Entity\\RecentlyReadType::load',
],
'#disabled' => TRUE,
];
$options = [];
foreach ($bundles as $key => $value) {
$options[$key] = ucfirst($key);
}
$form['types'] = [];
if (count($bundles) > 1) {
$form['types'] = [
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $entity
->get('types'),
'#title' => $this
->t('Track'),
'#required' => FALSE,
'#prefix' => '<div id="types">',
'#suffix' => '</div>',
];
}
return $form;
}