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 kifitos.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Terms of Service
type: module
core: 8.x
core_version_requirement: ">=8"
package: Kirjastot.fi
description: 'Terms of Service agreements'
dependencies:
Expand Down
4 changes: 2 additions & 2 deletions src/AgreementConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

interface AgreementConfigInterface {

const ROUTE_GUARD = 1;
const MESSAGE = 2;
public const ROUTE_GUARD = 1;
public const MESSAGE = 2;

public function getLabel();
public function setLabel($label);
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Agreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
}

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('Agreement ID'))
Expand Down
7 changes: 3 additions & 4 deletions src/EventSubscriber/KernelSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\kifitos\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Drupal;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Config\ConfigFactoryInterface;
Expand All @@ -13,8 +14,6 @@
use Drupal\user\UserDataInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpFoundation\Request;

class KernelSubscriber implements EventSubscriberInterface {
Expand All @@ -37,7 +36,7 @@ public function __construct(ControllerResolverInterface $controller_resolver, Ag
$this->userData = $user_data;
}

public function onController(FilterControllerEvent $event) {
public function onController(ControllerEvent $event) {
$user = Drupal::currentUser();

$controller = $event->getController();
Expand All @@ -60,7 +59,7 @@ public function onController(FilterControllerEvent $event) {

case AgreementConfigInterface::MESSAGE:
if ($event->getRequest()->isMethod('get')) {
drupal_set_message(new FormattableMarkup($agreement->getConfig()->getMessage(), []), 'warning', FALSE);
\Drupal::messenger()->addWarning(new FormattableMarkup($agreement->getConfig()->getMessage(), []), FALSE);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/EventSubscriber/RouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RouteSubscriber extends RouteSubscriberBase {
protected $entityManager;
protected $configStorage;

const ROUTE_GUARD = '_kifitos_route_access';
public const ROUTE_GUARD = '_kifitos_route_access';

public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
Expand All @@ -30,7 +30,7 @@ protected function alterRoutes(RouteCollection $collection) {
$route->setRequirement(self::ROUTE_GUARD, 'TRUE');
$route->setDefault('_kifitos', $config->id());
} else {
trigger_error(sprintf('%s: Route \'%d\' does not exist.', __CLASS__, $route_id));
trigger_error(sprintf('%s: Route \'%d\' does not exist.', self::class, $route_id));
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/Form/AgreementApproveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Drupal\kifitos\Form;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\Controller\EntityViewController;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\kifitos\Access\RouteGuard;
use Drupal\user\UserDataInterface;
Expand All @@ -14,18 +15,23 @@
class AgreementApproveForm extends ContentEntityForm {
protected $userData;

public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, UserDataInterface $user_data) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->userData = $user_data;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('entity.repository'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time'),
$container->get('user.data')
);
}

public function __construct(EntityManagerInterface $entity_manager, UserDataInterface $user_data) {
parent::__construct($entity_manager);
$this->userData = $user_data;
}

public function buildForm(array $form, FormStateInterface $form_state) {
parent::buildForm($form, $form_state);

Expand All @@ -52,6 +58,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}

public function view(array $form, FormStateInterface $form_state) {
$view = [];
$view['body'] = [
'#type' => 'fieldset',
'#title' => $this->t('Terms of service'),
Expand Down
2 changes: 1 addition & 1 deletion src/Form/AgreementConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

public function save(array $form, FormStateInterface $form_state) {
$this->entity->save();
drupal_set_message($this->t('Configuration updated.'));
$this->messenger()->addStatus($this->t('Configuration updated.'));
}
}