Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kifiform.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Form Bundle
type: module
core: 8.x
core_version_requirement: ">=8"
package: Kirjastot.fi
description: 'Provides custom form fields'
dependencies: {}
4 changes: 2 additions & 2 deletions kifiform.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rating-ajax:
public/js/kifiform-rating.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/once
view-counter:
js:
public/js/kifiform-view-counter.js: {}
Expand All @@ -30,4 +30,4 @@ autocomplete-tags:
public/js/kifiform-autocomplete-tags.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/once
8 changes: 6 additions & 2 deletions public/js/kifiform-autocomplete-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@

Drupal.behaviors.kifiFormAutoCompleteTags = {
attach: function(context, settings) {
var elements = $("input.form-autocomplete")
.once("kifiform-autocomplete-tags")
var elements = $(once("kifiform-autocomplete-tags", "input.form-autocomplete"))
.each(function(i, _input) {
var input = $(_input);

Expand All @@ -75,6 +74,9 @@

init_tags(input, proxy, tags);

// When enter is disabled, user cannot create new tags.
var disableEnter = settings.kifiform && settings.kifiform.disableEnter;

input
.on("autocompleteselect", function(event, ui) {
ui.item.autocompleted = true;
Expand All @@ -91,6 +93,8 @@
if (event.keyCode == KEY_ENTER && this.value.length > 0) {
event.preventDefault();

if (disableEnter) return;

append_value(proxy, this.value);
append_tag(input, tags, {label: this.value, value: this.value});

Expand Down
3 changes: 1 addition & 2 deletions public/js/kifiform-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

Drupal.behaviors.kifiFormContentRating = {
attach: function(context, settings) {
$(".field--type-kifiform-rating")
.once("kifiform-rating")
$(once("kifiform-rating", ".field--type-kifiform-rating"))
.each(function(i, _element) {
var element = $(_element);
var form = $(_element).find('.rating-form');
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ViewCounterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
Expand All @@ -18,7 +18,7 @@ class ViewCounterController extends ControllerBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('user.private_tempstore')
$container->get('tempstore.private')
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/Field/FieldType/RatingItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function defaultFieldSettings() {
}

public function isUserAllowedToVote() {
$store = \Drupal::service('user.private_tempstore')->get('kifiform');
$store = \Drupal::service('tempstore.private')->get('kifiform');
$key = sprintf('%s.%s.%s', $this->getEntity()->getEntityTypeId(), $this->getFieldDefinition()->getName(), $this->getEntity()->id());
return !$store->get($key);
}
Expand All @@ -116,7 +116,7 @@ public function addVote($vote, $lock_session = FALSE) {
}

if ($lock_session) {
$store = \Drupal::service('user.private_tempstore')->get('kifiform');
$store = \Drupal::service('tempstore.private')->get('kifiform');
$key = sprintf('%s.%s.%s', $this->getEntity()->getEntityTypeId(), $this->getFieldDefinition()->getName(), $this->getEntity()->id());
$store->set($key, TRUE);
}
Expand Down