Skip to content

Commit

Permalink
Merge branch 'release/8.x-1.1' into 8.x-1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
zero2one committed Feb 28, 2019
2 parents 771a0ab + 2958067 commit d37f143
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 51 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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

## [8.x-1.1]

**IMPORTANT : From now on, an API key is required due to a change in the API
endpoint.**

Change the API endpoint and set the API key value in the webservice
configuration after updating the module to this version.

See [service documentation](https://developer.gent.be/docs/dataset?service_id=openingsuren_service)
for more information about the endpoint.

### Changed

* DMOH-55: Changed the way to access the endpoint: added support to set the
required API key.

### Fixed

* DMOH-53: Fixed not unique element wrapper.
* DMOH-53: Fixed detecting if the element was submitted.

## [8.x-1.0]

### Added
Expand Down Expand Up @@ -153,6 +174,7 @@ for the same widget.
* DMOH-20: Added the opening hours field type.
* DMOH-21: Added the opening hours field widget.

[8.x-1.1]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.0...8.x-1.1
[8.x-1.0]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.0-beta1...8.x-1.0
[8.x-1.0-beta1]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.0-alpha16...8.x-1.0-beta1
[8.x-1.0-alpha16]: https://github.com/StadGent/drupal_module_opening-hours/compare/8.x-1.0-alpha15...8.x-1.0-alpha16
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ root and add following lines in the `repositories section:
"type": "package",
"package": {
"name": "drupal/opening-hours-widget",
"version": "0.0.3",
"version": "0.1.1",
"type": "drupal-library",
"dist": {
"url": "https://github.com/StadGent/npm_package_opening-hours-widget/releases/download/v0.0.3/opening-hours-widget.zip",
"url": "https://github.com/StadGent/npm_package_opening-hours-widget/releases/download/0.1.1/opening-hours-widget.zip",
"type": "zip"
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"source": "https://github.com/StadGent/drupal_module_opening-hours"
},
"require": {
"stadgent/services-opening-hours": "^1.0"
"stadgent/services-opening-hours": "^1.1"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.4",
Expand Down
1 change: 1 addition & 0 deletions js/opening-hours.binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

var options = {
'endpoint': settings.openingHours.endpoint,
'endpoint_key': settings.openingHours.endpoint_key,
'language': settings.openingHours.language,
'error' : function (request) {
var elem = getClosest(request.element, '.field');
Expand Down
10 changes: 6 additions & 4 deletions js/opening-hours.opening-hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
function OpeningHours(items, options) {
var defaults = {
endpoint: '',
endpoint_key: '',
language: 'en',
requestDate: this.getRequestDateFromUrl()
};
Expand All @@ -31,15 +32,16 @@ function OpeningHours(items, options) {
});

this.settings = defaults;
this.ohw = new OpeningHoursWidget({
endpoint: this.settings.endpoint
});

if (!this.settings.endpoint || !this.settings.endpoint.length) {
console.error('OpeningHours : Please provide an API endpoint.');
return this;
}

this.ohw = new OpeningHoursWidget({
endpoint: this.settings.endpoint,
endpoint_key: this.settings.endpoint_key
});

// Render the widgets for all found items.
for (var i = 0; i < items.length; i++) {
this.renderItemWidget(
Expand Down
4 changes: 2 additions & 2 deletions opening_hours.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library:
version: 0.0.3
version: 0.1.1
js:
/libraries/opening-hours-widget/dist/opening-hours-widget.min.js: { preprocess: false, minified: true }
/libraries/opening-hours-widget/dist/opening-hours-widget.min.js: { preprocess: false }

widget:
version: 1.x
Expand Down
2 changes: 2 additions & 0 deletions src/Element/OpeningHoursWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function getInfo() {
'#theme' => 'opening_hours_widget',
'#type' => NULL,
'#endpoint' => $this->openingHoursConfig->get('endpoint'),
'#endpoint_key' => $this->openingHoursConfig->get('key'),
'#service_id' => NULL,
'#channel_id' => NULL,
'#date' => NULL,
Expand All @@ -101,6 +102,7 @@ public static function preRenderMyElement($element) {
// Attach widget + endpoint configuration.
$element['#attached']['library'][] = 'opening_hours/widget';
$element['#attached']['drupalSettings']['openingHours']['endpoint'] = $element['#endpoint'];
$element['#attached']['drupalSettings']['openingHours']['endpoint_key'] = $element['#endpoint_key'];
$element['#attached']['drupalSettings']['openingHours']['language'] = $language;

return $element;
Expand Down
9 changes: 9 additions & 0 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#required' => TRUE,
];

$form['key'] = [
'#type' => 'textfield',
'#title' => $this->t('API key'),
'#description' => $this->t('Provide the API key if it is required to access the service.'),
'#default_value' => $config->get('key'),
'#required' => FALSE,
];

$form['cache_enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable cache'),
Expand Down Expand Up @@ -92,6 +100,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('opening_hours.settings')
->set('endpoint', $form_state->getValue('endpoint'))
->set('key', $form_state->getValue('key'))
->set('cache_enabled', (int) $form_state->getValue('cache_enabled'))
->save();

Expand Down
26 changes: 21 additions & 5 deletions src/Plugin/Field/FieldWidget/OpeningHoursWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\opening_hours\Plugin\Field\FieldWidget;

use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
Expand Down Expand Up @@ -143,10 +144,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
? $this->getChannelOptionsForService($currentService)
: [];

$wrapperId = sprintf(
'form-item-wrapper-%s-%d-opening-hours-channel',
$this->fieldDefinition->getName(),
$delta
// Unique channel wrapper id to update using ajax callback.
$wrapperId = Html::getUniqueId(
sprintf('%s-wrapper', $this->fieldDefinition->getName())
);

$element['opening_hours'] = [
Expand Down Expand Up @@ -477,7 +477,7 @@ protected function getChannelOptionsForService(Service $service) {
*/
protected function extractFormStateValues($delta, array $form, FormStateInterface $form_state) {
$values = [
'is_submitted' => !empty($form_state->getValues()),
'is_submitted' => $this->isFormSubmitted($form_state),
'service' => NULL,
'channel' => NULL,
];
Expand All @@ -504,4 +504,20 @@ protected function extractFormStateValues($delta, array $form, FormStateInterfac
return $values;
}

/**
* Check if the form was submitted by changing the service.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state to get the triggering element from.
*
* @return bool
* Is submitted.
*/
protected function isFormSubmitted(FormStateInterface $form_state) {
$trigger = $form_state->getTriggeringElement();

return !empty($trigger['#autocomplete_route_name'])
&& $trigger['#autocomplete_route_name'] === 'opening_hours.service.autocomplete';
}

}
10 changes: 5 additions & 5 deletions src/Services/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class ClientService extends StadGentClient {
public function __construct(ConfigFactoryInterface $config_factory) {
$config = $config_factory->get('opening_hours.settings');

$configuration = new Configuration($config->get('endpoint'));
$guzzleClient = new GuzzleClient(
[
'base_uri' => $configuration->getUri(),
]
$configuration = new Configuration(
$config->get('endpoint'),
$config->get('key')
);

$guzzleClient = new GuzzleClient(['base_uri' => $configuration->getUri()]);

parent::__construct($guzzleClient, $configuration);
}

Expand Down
38 changes: 23 additions & 15 deletions translations/general.pot
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2019-01-07 12:05+0100\n"
"POT-Creation-Date: 2019-02-28 08:43+0100\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
Expand All @@ -42,7 +42,7 @@ msgstr ""
msgid "The <a href=\"@opening_hours\" target=\"_blank\">opening hours widget</a> plugin is missing. See <a href=\"@readme\">README.md</a> for instructions on how to download and extract it."
msgstr ""

#: modules/contrib/opening_hours/opening_hours.info.yml:0 modules/contrib/opening_hours/opening_hours.links.menu.yml:0 modules/contrib/opening_hours/opening_hours.routing.yml:0 modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:20
#: modules/contrib/opening_hours/opening_hours.info.yml:0 modules/contrib/opening_hours/opening_hours.links.menu.yml:0 modules/contrib/opening_hours/opening_hours.routing.yml:0 modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:21
msgid "Opening Hours"
msgstr ""

Expand Down Expand Up @@ -91,14 +91,22 @@ msgid "Provide the endpoint URL including the API version number."
msgstr ""

#: modules/contrib/opening_hours/src/Form/ConfigForm.php:63
msgid "Enable cache"
msgid "API key"
msgstr ""

#: modules/contrib/opening_hours/src/Form/ConfigForm.php:64
msgid "Provide the API key if it is required to access the service."
msgstr ""

#: modules/contrib/opening_hours/src/Form/ConfigForm.php:71
msgid "Enable cache"
msgstr ""

#: modules/contrib/opening_hours/src/Form/ConfigForm.php:72
msgid "This will enable caching of the responses from the API."
msgstr ""

#: modules/contrib/opening_hours/src/Form/ConfigForm.php:78
#: modules/contrib/opening_hours/src/Form/ConfigForm.php:86
msgid "Provide an absolute URL."
msgstr ""

Expand Down Expand Up @@ -246,55 +254,55 @@ msgstr ""
msgid "Adds a field to select the Service and its Channel to show its opening hours for."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:162
#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:163
msgid "Service"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9
msgid "Service label"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:174
#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9 modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:176
msgid "Channel"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldType/OpeningHoursItem.php:9
msgid "Channel label"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:152
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:153
msgid "Opening hours"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:153
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:154
msgid "Select a Service and one of its Channels to link this item with Opening Hours."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:177
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:179
msgid "Select first a Service"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:183
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:185
msgid "- Select -"
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:272
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:274
msgid "Service does not exists."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:281
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:283
msgid "Service is required when Channel is set."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:289
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:291
msgid "Channel is required when Service is set."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:298
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:300
msgid "Channel does not exists for this Service."
msgstr ""

#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:405;432
#: modules/contrib/opening_hours/src/Plugin/Field/FieldWidget/OpeningHoursWidget.php:407;434
msgid "API returned : @message"
msgstr ""

Loading

0 comments on commit d37f143

Please sign in to comment.