Skip to content

Commit

Permalink
Merge branch 'release/8.x-1.0-aplha1' into 8.x-1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
zero2one committed Dec 13, 2017
2 parents 075df8c + 3f53ce8 commit 3d7d9ad
Show file tree
Hide file tree
Showing 13 changed files with 847 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

All Notable changes to `drupal/opening-hours` module.

## [Unreleased]
## [8.x-1.0-aplha1]

### Added
* DMOH-19: Added service configuration form.
* DMOH-20: Added the opening hours field type.
* DMOH-21: Added the opening hours field widget.

[8.x-1.0-aplha1]: https://github.com/StadGent/drupal_module_opening-hours/releases/tag/8.x-1.0-aplha1
[Unreleased]: https://github.com/StadGent/drupal_module_opening-hours/compare/master...develop
22 changes: 22 additions & 0 deletions opening_hours.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* Module hooks.
*/

/**
* Implements hook_theme().
*/
function opening_hours_theme($existing, $type, $theme, $path) {
return [
'opening_hours_opennow' => [
'template' => 'opening-hours-opennow',
'path' => $path . '/templates',
'variables' => [
'serviceId' => NULL,
'channelId' => NULL,
],
],
];
}
2 changes: 1 addition & 1 deletion opening_hours.permissions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configure opening hours:
title: 'Configure Opening Hours Service'
description: 'Give access to the Opening Hours service configuration page.'
restrict access: TRUE
restrict access: true
8 changes: 8 additions & 0 deletions opening_hours.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ opening_hours.admin_config:
_title: 'Opening Hours'
requirements:
_permission: 'configure opening hours'

opening_hours.service.autocomplete:
path: opening-hours/autocomplete
defaults:
_controller: Drupal\opening_hours\Controller\ServiceController::autocomplete
_title: 'Lookup services'
requirements:
_access: 'TRUE'
20 changes: 20 additions & 0 deletions opening_hours.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
opening_hours.client:
class: Drupal\opening_hours\Services\ClientService
arguments: [ '@config.factory' ]
opening_hours.service:
class: StadGent\Services\OpeningHours\Service\Service\ServiceService
factory: Drupal\opening_hours\Services\ServiceFactory::createServiceService
arguments: [ '@opening_hours.client' ]
opening_hours.channel:
class: StadGent\Services\OpeningHours\Service\Channel\ChannelService
factory: Drupal\opening_hours\Services\ServiceFactory::createChannelService
arguments: [ '@opening_hours.client' ]
opening_hours.channel_opening_hours:
class: StadGent\Services\OpeningHours\Service\Channel\ChannelService
factory: Drupal\opening_hours\Services\ServiceFactory::createChannelOpeningHoursService
arguments: [ '@opening_hours.client' ]
opening_hours.channel_opening_hours_html:
class: StadGent\Services\OpeningHours\Service\Channel\ChannelService
factory: Drupal\opening_hours\Services\ServiceFactory::createChannelOpeningHoursHtmlService
arguments: [ '@opening_hours.client' ]
78 changes: 78 additions & 0 deletions src/Controller/ServiceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Drupal\opening_hours\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\StringTranslation\TranslationInterface;
use StadGent\Services\OpeningHours\Service\Service\ServiceService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* Controller to get AutoComplete functionality when searching for a Service.
*
* @package Drupal\opening_hours\Controller
*/
class ServiceController extends ControllerBase {
/**
* The Opening Hours Service service.
*
* @var \StadGent\Services\OpeningHours\Service\Service\ServiceService
*/
protected $serviceService;

/**
* Constructor.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $stringTranslation
* The String translation service.
* @param \StadGent\Services\OpeningHours\Service\Service\ServiceService $serviceService
* The Opening hours Service service.
*/
public function __construct(TranslationInterface $stringTranslation, ServiceService $serviceService) {
$this->setStringTranslation($stringTranslation);
$this->serviceService = $serviceService;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/* @var $stringTranslation \Drupal\Core\StringTranslation\TranslationInterface */
$stringTranslation = $container->get('string_translation');

/* @var $serviceService \StadGent\Services\OpeningHours\Service\Service\ServiceService */
$serviceService = $container->get('opening_hours.service');

return new static($stringTranslation, $serviceService);
}

/**
* Lookup Services through an autocomplete field.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object containing the search string.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
* A JSON response containing the autocomplete suggestions.
*/
public function autocomplete(Request $request) {
$matches = [];

$search = $request->query->get('q');
$services = $this->serviceService->searchByLabel($search);
/* @var $service \StadGent\Services\OpeningHours\Value\Service */
foreach ($services as $service) {
$value = sprintf('%s [%d]', $service->getLabel(), $service->getId());

$matches[] = [
'value' => $value,
'label' => $service->getLabel(),
];
}

return new JsonResponse($matches);
}

}
2 changes: 1 addition & 1 deletion src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
else {
$form_state->setValue(
'endpoint',
rtrim($form_state->getValue('endpoint'), '/')
rtrim($form_state->getValue('endpoint'), '/') . '/'
);
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/Plugin/Field/FieldFormatter/OpenNowFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Drupal\opening_hours\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;

/**
* Open Now formatter for the opening_hours field item.
*
* @FieldFormatter(
* id = "opening_hours_opennow",
* label = @Translation("Open now"),
* field_types = {
* "opening_hours"
* }
* )
*/
class OpenNowFormatter extends FormatterBase {

/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];

foreach ($items as $delta => $item) {
$element[$delta] = [
'#theme' => 'opening_hours_opennow',
'#serviceId' => $item->service,
'#channelId' => $item->channel,
];
}

return $element;
}

}
66 changes: 66 additions & 0 deletions src/Plugin/Field/FieldType/OpeningHoursItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Drupal\opening_hours\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;

/**
* Provides a field type "Entrance Fee".
*
* @FieldType(
* id = "opening_hours",
* label = @Translation("Opening Hours"),
* description = @Translation("Adds a field to select the Service and its Channel to show its opening hours for."),
* category = @Translation("Web services"),
* module = "opening_hours",
* default_formatter = "opening_hours_opennow",
* default_widget = "opening_hours",
* column_groups = {
* "service" = {
* "label" = @Translation("Service"),
* "translatable" = TRUE
* },
* "channel" = {
* "label" = @Translation("Channel"),
* "translatable" = TRUE
* },
* },
* )
*/
class OpeningHoursItem extends FieldItemBase {

/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'service' => [
'description' => 'The service record ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
],
'channel' => [
'description' => 'The channel record ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
],
],
];
}

/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = [];
$properties['service'] = DataDefinition::create('string');
$properties['channel'] = DataDefinition::create('string');
return $properties;
}

}
Loading

0 comments on commit 3d7d9ad

Please sign in to comment.