class AnimateEditForm in Animate Any 8
Provides a edit form for edit/update the animation data from Animation list.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\animate_any\Form\AnimateEditForm
Expanded class hierarchy of AnimateEditForm
1 string reference to 'AnimateEditForm'
File
- src/
Form/ AnimateEditForm.php, line 11
Namespace
Drupal\animate_any\FormView source
class AnimateEditForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'animate_edit_form';
}
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;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$op = (string) $form_state
->getValue('op');
if ($op == $this
->t('Update Settings')) {
$parent = $form_state
->getValue('parent_class');
if (empty($parent)) {
$form_state
->setErrorByName("parent_class", $this
->t("Please select parent class"));
}
foreach ($form_state
->getValue('animate_fieldset') as $key => $value) {
if (empty($value['section_identity'])) {
$form_state
->setErrorByName("animate_fieldset][{$key}][section_identity", $this
->t("Please select section identity for row @key", [
'@key' => $key,
]));
}
if ($value['section_event'] == 'none') {
$form_state
->setRebuild();
$form_state
->setErrorByName("animate_fieldset][{$key}][section_event", $this
->t("Please select section event for row @key", [
'@key' => $key,
]));
}
if ($value['section_animation'] == 'none') {
$form_state
->setErrorByName("animate_fieldset][{$key}][section_animation", $this
->t("Please select section animation for row @key", [
'@key' => $key,
]));
}
}
}
}
/**
* Submit for animate_any_settings.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Update the data for current element.
$parent = $form_state
->getvalue('parent_class');
$aid = $form_state
->getvalue('aid');
$identifiers = json_encode($form_state
->getvalue('animate_fieldset'));
$data = \Drupal::database()
->update('animate_any_settings');
$data
->fields([
'parent' => $parent,
'identifier' => $identifiers,
]);
$data
->condition('aid', $aid);
$valid = $data
->execute();
if ($valid) {
$this
->messenger()
->addMessage($this
->t('Animation settings updated.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnimateEditForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
AnimateEditForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AnimateEditForm:: |
public | function |
Submit for animate_any_settings. Overrides FormInterface:: |
|
AnimateEditForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |