Skip to content
Snippets Groups Projects
Commit d3f2a065 authored by Kevin Rice's avatar Kevin Rice
Browse files

changes format field to text, fixes misc errors with update

parent cb8a596c
No related branches found
Tags 8.x-2.0-alpha17
1 merge request!2Resolve #3347809 "Add readme.md file"
......@@ -5,28 +5,36 @@ use Drupal\simple_survey\Entity\Sql\SurveyAnswerStorageSchema;
use Drupal\simple_survey\Entity\Sql\SurveyResponseStorageSchema;
/**
* Sets indicies on response tables.
* Sets indicies on answer tables.
*/
function simple_survey_update_9001() {
$manager = \Drupal::entityDefinitionUpdateManager();
$surveyAnswer = $manager->getEntityType('survey_answer')
->setHandlerClass('storage_schema', SurveyAnswerStorageSchema::class);
$manager->updateEntityType($surveyAnswer);
}
/**
* Sets indicies on response tables.
*/
function simple_survey_update_9002() {
$manager = \Drupal::entityDefinitionUpdateManager();
$surveyResponse = $manager->getEntityType('survey_response')
->setHandlerClass('storage_schema', SurveyResponseStorageSchema::class);
$manager->updateEntityType($surveyAnswer);
$manager->updateEntityType($surveyResponse);
}
/**
* Sets default value for OMB expiration format config.
*/
function simple_survey_update_9002() {
$survey_ids = SimpleSurvey::loadMultiple();
function simple_survey_update_9003() {
$surveys = SimpleSurvey::loadMultiple();
foreach ($survey_ids as $survey_id) {
$survey = SimpleSurvey::load($survey_id);
foreach ($surveys as $survey) {
$survey->set('ombExpirationFormat', 'Y-m-d');
$survey->save();
}
......
......@@ -176,6 +176,7 @@ function simple_survey_queue_bq_submissions() {
function simple_survey_page_attachments(array &$attachments) {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter */
$dateFormatter = \Drupal::service('date.formatter');
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = \Drupal::service('module_handler');
if (!\Drupal::service('router.admin_context')->isAdminRoute()) {
......@@ -184,11 +185,11 @@ function simple_survey_page_attachments(array &$attachments) {
if ($survey) {
$omb_expiration_date = $survey->get('ombExpiration');
if (isset($survey->get('ombExpiration'))) {
$date_format = isset($survey->get('ombExpirationFormat')) ?
if ($omb_expiration_date) {
$date_format = $survey->get('ombExpirationFormat') ?
$survey->get('ombExpirationFormat') : 'Y-m-d';
$omb_expiration_date = $dateFormatter
->format(strtotime($omb_expiration_date), $date_format);
->format(strtotime($omb_expiration_date), 'custom', $date_format);
}
$configOutput = [
......@@ -215,7 +216,7 @@ function simple_survey_page_attachments(array &$attachments) {
"survey" => $survey->id(),
"displayCooldown" => $survey->get('displayCooldown') ?: 1,
"answeredDisplayCooldown" => $survey->get('answeredDisplayCooldown') ?: 1,
"modulePath" => '/' . \Drupal::service('module_handler')->getModule('simple_survey')->getPath(),
"modulePath" => '/' . $moduleHandler->getModule('simple_survey')->getPath(),
];
$attachments['#attached']['library'][] = 'simple_survey/simple_survey';
......
......@@ -27,6 +27,8 @@ class SurveyResponseStorageSchema extends SqlContentEntityStorageSchema {
],
];
}
return $schema;
}
/**
......
......@@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
* id = "survey_answer",
* label = @Translation("Survey Answer"),
* handlers = {
* "storage_schema" = "Drupal\simple_survey\Entity\Sql\SurveyAnswerStorageSchema,
* "storage_schema" = "Drupal\simple_survey\Entity\Sql\SurveyAnswerStorageSchema",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* },
* base_table = "survey_answer",
......
......@@ -23,7 +23,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
* plural = "@count survey responses",
* ),
* handlers = {
* "storage_schema" = "Drupal\simple_survey\Entity\Sql\SurveyAnswerStorageSchema,
* "storage_schema" = "Drupal\simple_survey\Entity\Sql\SurveyAnswerStorageSchema",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\simple_survey\Entity\SurveyResponseListBuilder",
* "views_data" = "Drupal\simple_survey\Entity\SurveyResponseViewsData",
......
......@@ -128,17 +128,17 @@ class SimpleSurveyForm extends EntityForm {
'#default_value' => $simpleSurvey->get('ombExpiration'),
];
$url = Url::fromUri('https://www.php.net/manual/en/datetime.format.php');
$form['privacy']['ombExpirationFormat'] = [
'#type' => 'select',
'#type' => 'textfield',
'#name' => 'ombExpirationFormat',
'#title' => $this->t('OMB Expiration Date Format'),
'#description' => $this->t('The format the date should appear in.'),
'#description' => $this->t('Field expects conventions found at @link. Example "m-d-Y" will display MM-DD-YYYY', [
'@link' => Link::fromTextAndUrl('PHP Date Formats', $url)->toString(),
]),
'#default_value' => !is_null($simpleSurvey->get('ombExpirationFormat')) ?
$simpleSurvey->get('ombExpirationFormat') : 'Y-m-d',
'#options' => [
"Y-m-d" => $this->t('YYYY-MM-DD'),
"d-m-Y" => $this->t('DD-MM-YYYY'),
],
];
$form['privacy']['ombId'] = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment