diff --git a/includes/vuejs.admin.inc b/includes/vuejs.admin.inc new file mode 100644 index 0000000000000000000000000000000000000000..c499500d2d4953a026b831583a975122dcf37a34 --- /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 dea18b360340334d8c9a556071d3e4553b2e7ef0..ba9de3b6590491f22db1a73d43e6d33209cd066a 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.')); + } + } +}