public function AnimateEditForm::buildForm in Animate Any 8
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
- src/
Form/ AnimateEditForm.php, line 20
Class
- AnimateEditForm
- Provides a edit form for edit/update the animation data from Animation list.
Namespace
Drupal\animate_any\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $element = NULL) {
$fetch = \Drupal::database()
->select("animate_any_settings", "a");
$fetch
->fields('a');
$fetch
->condition('a.aid', $element);
$fetch_results = $fetch
->execute()
->fetchAssoc();
$form = [];
$form['#attached']['library'][] = 'animate_any/animate';
$form['#tree'] = TRUE;
$form['parent_class'] = [
'#title' => 'Add Parent Class',
'#description' => $this
->t('You can add body class like <em>body.front (for front page)</em> OR class with dot(.) prefix and Id with hash(#) prefix.'),
'#type' => 'textfield',
'#default_value' => $fetch_results['parent'],
];
$form['aid'] = [
'#type' => 'hidden',
'#default_value' => $element,
];
$form['animate_fieldset'] = [
'#prefix' => '<div id="item-fieldset-wrapper">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#theme' => 'table',
'#header' => [],
'#rows' => [],
'#attributes' => [
'class' => 'animation',
],
];
// Json decode to get json to array.
$data = json_decode($fetch_results['identifier']);
foreach ($data as $key => $value) {
$section_identity = [
'#type' => 'textfield',
'#title' => $this
->t('Section identity'),
'#default_value' => $value->section_identity,
'#description' => $this
->t("Add class with dot(.) prefix and Id with hash(#) prefix."),
];
$section_event = [
'#title' => $this
->t('Select event'),
'#type' => 'select',
'#options' => animate_on_event(),
'#attributes' => [
'class' => [
'select_event',
],
],
'#default_value' => $value->section_event,
];
$section_animation = [
'#type' => 'select',
'#options' => animate_any_options(),
'#title' => $this
->t('Section Animation'),
'#default_value' => $value->section_animation,
'#attributes' => [
'class' => [
'select_animate',
],
],
];
$animation = [
'#markup' => 'ANIMATE ANY',
'#prefix' => '<h1 id="animate" class="" style="font-size: 30px;">',
'#suffix' => '</h1>',
];
$form['animate_fieldset'][$key] = [
'section_identity' => &$section_identity,
'section_event' => &$section_event,
'section_animation' => &$section_animation,
'animation' => &$animation,
];
$form['animate_fieldset']['#rows'][$key] = [
[
'data' => &$section_identity,
],
[
'data' => &$section_event,
],
[
'data' => &$section_animation,
],
[
'data' => &$animation,
],
];
unset($section_identity);
unset($section_event);
unset($section_animation);
unset($animation);
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Update Settings'),
];
return $form;
}