Skip to content

Commit

Permalink
Merge pull request #3 from mkdok/main
Browse files Browse the repository at this point in the history
feat: Add min/max Grade fields for Session node
  • Loading branch information
podarok authored Jun 5, 2023
2 parents a9fb775 + f87f11b commit 467743d
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 82 deletions.
174 changes: 92 additions & 82 deletions config/install/core.entity_form_display.node.session.default.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ dependencies:
- field.field.node.session.field_session_instructor
- field.field.node.session.field_session_location
- field.field.node.session.field_session_max_age
- field.field.node.session.field_session_max_grade
- field.field.node.session.field_session_mbr_price
- field.field.node.session.field_session_min_age
- field.field.node.session.field_session_min_grade
- field.field.node.session.field_session_nmbr_price
- field.field.node.session.field_session_online
- field.field.node.session.field_session_plocation
Expand Down Expand Up @@ -240,6 +242,8 @@ content:
region: content
hidden:
field_session_instructor: true
field_session_max_grade: true
field_session_min_grade: true
field_session_room: true
langcode: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_session_max_grade
- node.type.session
module:
- options
id: node.session.field_session_max_grade
field_name: field_session_max_grade
entity_type: node
bundle: session
label: 'Max Grade'
description: 'Select List with maximum Grade option.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_session_min_grade
- node.type.session
module:
- options
id: node.session.field_session_min_grade
field_name: field_session_min_grade
entity_type: node
bundle: session
label: 'Min Grade'
description: 'Select List with minimum Grade options.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
20 changes: 20 additions & 0 deletions config/install/field.storage.node.field_session_max_grade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- node
- options
id: node.field_session_max_grade
field_name: field_session_max_grade
entity_type: node
type: list_string
settings:
allowed_values: { }
allowed_values_function: '\Drupal\openy_node_session\SessionGrade::getGrades'
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
20 changes: 20 additions & 0 deletions config/install/field.storage.node.field_session_min_grade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
module:
- node
- options
id: node.field_session_min_grade
field_name: field_session_min_grade
entity_type: node
type: list_string
settings:
allowed_values: { }
allowed_values_function: '\Drupal\openy_node_session\SessionGrade::getGrades'
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
19 changes: 19 additions & 0 deletions openy_node_session.install
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,22 @@ function openy_node_session_update_8014() {
}
}
}

/**
* Add new fields for Min/Max Grade values.
*/
function openy_node_session_update_8015() {
$config_dir = \Drupal::service('extension.list.module')->getPath('openy_node_session') . '/config/install/';

// Add two new fields.
$config_importer = \Drupal::service('openy_upgrade_tool.importer');
$config_importer->setDirectory($config_dir);
$config_importer->importConfigs([
'field.field.node.session.field_session_max_grade',
'field.field.node.session.field_session_min_grade',
'field.storage.node.field_session_max_grade',
'field.storage.node.field_session_min_grade',
'core.entity_view_display.node.session.default',
'core.entity_form_display.node.session.default',
]);
}
37 changes: 37 additions & 0 deletions src/SessionGrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Drupal\openy_node_session;

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Provides logic for listing session's grade types.
*/
final class SessionGrade {

/**
* Gets the list of all available session's grade types.
*
* @return array
* The labels, keyed by ID.
*/
public static function getGrades() : array {
return [
'PRE_K' => new TranslatableMarkup('Pre K'),
'K' => new TranslatableMarkup('Kindergarten'),
'1' => new TranslatableMarkup('Grade 1'),
'2' => new TranslatableMarkup('Grade 2'),
'3' => new TranslatableMarkup('Grade 3'),
'4' => new TranslatableMarkup('Grade 4'),
'5' => new TranslatableMarkup('Grade 5'),
'6' => new TranslatableMarkup('Grade 6'),
'7' => new TranslatableMarkup('Grade 7'),
'8' => new TranslatableMarkup('Grade 8'),
'9' => new TranslatableMarkup('Grade 9'),
'10' => new TranslatableMarkup('Grade 10'),
'11' => new TranslatableMarkup('Grade 11'),
'12' => new TranslatableMarkup('Grade 12'),
];
}

}

0 comments on commit 467743d

Please sign in to comment.