Skip to content
Snippets Groups Projects
Commit 1594e4af authored by Eduard Reñé Claramunt's avatar Eduard Reñé Claramunt Committed by Sascha Grossenbacher
Browse files

Issue #2648836 by edurenye, Bambell: Alert the user that deleting a choice...

Issue #2648836 by edurenye, Bambell: Alert the user that deleting a choice will delete the votes on it
parent 5c951905
No related branches found
Tags 8.x-1.10 8.x-1.10-rc1 8.x-1.11
No related merge requests found
(function ($, Drupal) {
$('.poll-existing-choice').on('focus', function (event) {
$(document).once('poll-existing-choice').each(function () {
$(Drupal.theme('pollChoiceDeleteWarning')).insertBefore($('#choice-values')).hide().fadeIn('slow');
});
});
$.extend(Drupal.theme, /** @lends Drupal.theme */{
/**
* @return {string}
* Markup for the warning.
*/
pollChoiceDeleteWarning: function () {
return '<div class="messages messages--warning" role="alert">' + Drupal.t('* Deleting a choice will delete the votes on it!') + '</div>';
}
});
})(jQuery, Drupal);
......@@ -4,3 +4,7 @@ drupal.poll-links:
component:
css/poll.base.css: {}
css/poll.theme.css: {}
admin:
js:
js/poll.admin.js: {}
......@@ -9,6 +9,7 @@ namespace Drupal\poll\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
/**
* Form controller for the poll edit forms.
......@@ -19,11 +20,20 @@ class PollForm extends ContentEntityForm {
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$poll = $this->entity;
$form['#title'] = $this->t('Edit @label', ['@label' => $poll->label()]);
return parent::form($form, $form_state, $poll);
foreach ($form['choice']['widget'] as $key => $choice) {
if (is_int($key) && $form['choice']['widget'][$key]['choice']['#default_value'] != NULL) {
$form['choice']['widget'][$key]['choice']['#attributes'] = ['class' => ['poll-existing-choice']];
}
}
$form['#attached'] = ['library' => ['poll/admin']];
return $form;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment