public function RelationGenerate::buildForm in Relation 8
Same name and namespace in other branches
- 8.2 relation_devel/src/Form/RelationGenerate.php \Drupal\relation_devel\Form\RelationGenerate::buildForm()
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 FormInterface::buildForm
File
- relation_devel/
src/ Form/ RelationGenerate.php, line 28 - Contains \Drupal\relation_devel\Form\RelationGenerate.
Class
- RelationGenerate
- Provides a form for generating dummy relations.
Namespace
Drupal\relation_devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$relation_types = RelationType::loadMultiple();
if (empty($relation_types)) {
$form['explanation']['#markup'] = t("You must create a relation type before you can generate relations.");
return $form;
}
foreach ($relation_types as $relation_type) {
$options[$relation_type
->id()] = array(
'label' => $relation_type
->label(),
);
}
$header = array(
'label' => t('Relation type'),
);
$form['relation_types'] = array(
'#type' => 'tableselect',
'#title' => t('Relation types'),
'#description' => t('Select relation types to create relations from. If no types are selected, relations will be generated for all types.'),
'#options' => $options,
'#header' => $header,
);
$form['relation_kill'] = array(
'#type' => 'checkbox',
'#title' => t('Delete all relations in these relation types before generating new relations'),
);
$form['relation_number'] = array(
'#type' => 'number',
'#title' => t('How many relations would you like to generate of each type?'),
'#default_value' => 10,
'#size' => 10,
'#min' => 0,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
);
return $form;
}