From 453939b2c60105ed3a30c7b3ca22d310083f81c7 Mon Sep 17 00:00:00 2001 From: Goto Hayato <habita.gh@gmail.com> Date: Sat, 4 Nov 2017 11:50:43 +0900 Subject: [PATCH] Issue #2920956 by hgoto: Add the function and UI to change the versions. --- includes/vuejs.admin.inc | 57 ++++++++++++++++++++++++++++++++++++++++ vuejs.module | 42 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 includes/vuejs.admin.inc diff --git a/includes/vuejs.admin.inc b/includes/vuejs.admin.inc new file mode 100644 index 0000000..c499500 --- /dev/null +++ b/includes/vuejs.admin.inc @@ -0,0 +1,57 @@ +<?php + +/** + * @file + * Provides admin page callbacks for vuejs module. + */ + +/** + * Form builder for admin/config/development/vuejs. + */ +function vuejs_settings_form($form, &$form_state) { + $libraries = array( + 'vue' => array( + 'default' => 'v2.5.2', + ), + 'vue_router' => array( + 'default' => 'v3.0.1', + ), + 'vuex' => array( + 'default' => 'v3.0.0', + ), + ); + + foreach ($libraries as $library_name => $versions) { + $variable_name = 'vuejs_version_' . $library_name; + + $current_version = variable_get($variable_name, $versions['default']); + + $form[$library_name] = array( + '#type' => 'fieldset', + '#title' => str_replace('_', '-', $library_name), + ); + + $form[$library_name][$variable_name] = array( + '#type' => 'textfield', + '#title' => t('Version'), + '#size' => 9, + '#required' => TRUE, + '#default_value' => $current_version, + '#description' => t('The defaule version is "@version".', array( + '@version' => $versions['default'], + )), + '#element_validate' => array('vuejs_validate_version_text'), + ); + } + + $form['#submit'][] = 'vuejs_settings_form_submit'; + + return system_settings_form($form); +} + +/** + * Additional submit callback for vuejs_settings_form(). + */ +function vuejs_settings_form_submit(&$form, &$form_state) { + libraries_cache_clear(); +} diff --git a/vuejs.module b/vuejs.module index dea18b3..ba9de3b 100644 --- a/vuejs.module +++ b/vuejs.module @@ -80,6 +80,33 @@ function vuejs_libraries_info() { return $libraries; } +/** + * Implements hook_permission(). + */ +function vuejs_permission() { + return array( + 'administer vuejs configuration' => array( + 'title' => t('Administer vuejs configuration'), + 'restrict access' => TRUE, + ), + ); +} + +/** + * Implements hook_menu(). + */ +function vuejs_menu() { + $items['admin/config/development/vuejs'] = array( + 'title' => 'Vue.js', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('vuejs_settings_form'), + 'access arguments' => array('administer vuejs configuration'), + 'file' => 'includes/vuejs.admin.inc', + ); + + return $items; +} + /** * Theme functions. */ @@ -91,3 +118,18 @@ function vuejs_libraries_info() { /** * Other functions. */ + +/** + * Validator function for text fields for versions. + * + * @see vuejs_settings_form() + */ +function vuejs_validate_version_text($element, &$form_state, $form) { + if (!empty($element['#value'])) { + $value = $element['#value']; + $result = preg_match('/^v?[\d\.]+$/', $value); + if (empty($result)) { + form_error($element, t('The version is not valid.')); + } + } +} -- GitLab