Skip to content

Commit

Permalink
8.1.11
Browse files Browse the repository at this point in the history
- Graceful fallback if the localist base url is not set
- Updated localist URL references (#26)
  • Loading branch information
pookmish authored Apr 5, 2022
2 parents 30f3f21 + c97cc2d commit b6f34c4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Stanford Fields


8.x-1.11
--------------------------------------------------------------------------------
_Release Date: 2022-04-05_

- Graceful fallback if the localist base url is not set
- Updated localist URL references (#26)


8.x-1.10
--------------------------------------------------------------------------------
_Release Date: 2022-03-17_
Expand Down
8 changes: 7 additions & 1 deletion src/Plugin/Field/FieldWidget/LocalistUrlWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ public function settingsSummary() {
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);

// Fallback to inherited link widget if the base_url is not set.
if (!$this->getSetting('base_url')) {
return $element;
}
$element['uri']['#access'] = FALSE;
$element['title']['#access'] = FALSE;
$element['attributes']['#access'] = FALSE;
Expand Down Expand Up @@ -196,6 +199,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
* {@inheritDoc}
*/
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
if (!$this->getSetting('base_url')) {
return parent::massageFormValues($values, $form, $form_state);
}

foreach ($values as $delta => &$value) {

Expand Down
2 changes: 1 addition & 1 deletion stanford_fields.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ type: module
description: 'Field types, widgets and formatters to enhance Drupal and Contrib.'
core_version_requirement: ^8 || ^9
package: Stanford
version: 8.x-1.10
version: 8.x-1.11
dependencies:
- drupal:field
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function setUp(): void {
$entity_form_display->setComponent('su_localist_url', [
'type' => 'localist_url',
'settings' => [
'base_url' => 'https://stanford.enterprise.localist.com',
'base_url' => 'https://events.stanford.edu',
],
])->removeComponent('created')->save();

Expand All @@ -97,7 +97,7 @@ public function testWidgetForm() {

$node->set('su_localist_url', [
[
'uri' => 'https://stanford.enterprise.localist.com/api/2/events?group_id=37955145294460&days=365',
'uri' => 'https://events.stanford.edu/api/2/events?group_id=37955145294460&days=365',
'title' => '',
'options' => '',
],
Expand All @@ -115,7 +115,7 @@ public function testWidgetForm() {
$widget_value = $form['su_localist_url']['widget'];

$this->assertIsArray($widget_value[0]);
$this->assertEquals('https://stanford.enterprise.localist.com/api/2/events?group_id=37955145294460&days=365', $widget_value[0]['uri']['#default_value']);
$this->assertEquals('https://events.stanford.edu/api/2/events?group_id=37955145294460&days=365', $widget_value[0]['uri']['#default_value']);
$this->assertEquals('details', $widget_value[0]['filters']['#type']);
$this->assertIsArray($widget_value[0]['filters']['type']['event_audience']);
$this->assertIsArray($widget_value[0]['filters']['type']['event_audience']['#options']);
Expand Down Expand Up @@ -152,21 +152,21 @@ public function testSettingsForm() {
$config = [
'field_definition' => $field_def,
'settings' => [
'base_url' => 'https://stanford.enterprise.localist.com',
'base_url' => 'https://events.stanford.edu',
],
'third_party_settings' => [],
];

$widget = LocalistUrlWidget::create(\Drupal::getContainer(), $config, '', $definition);
$summary = $widget->settingsSummary();
$this->assertCount(1, $summary);
$this->assertEquals('Base URL: https://stanford.enterprise.localist.com', (string) $summary[0]);
$this->assertEquals('Base URL: https://events.stanford.edu', (string) $summary[0]);

$form = [];
$form_state = new FormState();
$element = $widget->settingsForm($form, $form_state);
$this->assertCount(4, $element);
$this->assertEquals("https://stanford.enterprise.localist.com", $element['base_url']['#default_value']);
$this->assertEquals("https://events.stanford.edu", $element['base_url']['#default_value']);
$this->assertArrayHasKey('select_distinct', $element);
$element['#parents'] = [];

Expand All @@ -187,7 +187,7 @@ public function testSettingsForm() {
protected function getValidValue() {
return [
[
'uri' => 'https://stanford.enterprise.localist.com/api/2/events?group_id=37955145294460&days=365',
'uri' => 'https://events.stanford.edu/api/2/events?group_id=37955145294460&days=365',
'title' => '',
'attributes' => [],
'filters' => [
Expand Down

0 comments on commit b6f34c4

Please sign in to comment.